Open ammarfaizi2 opened 3 years ago
All right, I will get tmute
and warn
part,
but before that, how bot will unmute the user after the specified time passed?
I found this code here :
tmp = do_mute(thread, reply_text, &(const tga_restrict_cm_t){
.chat_id = tge_get_chat_id(evt),
.user_id = target_uid,
.until_date = 0,
.permissions = {
.can_send_messages = is_unmute,
.can_send_media_messages = is_unmute,
.can_send_polls = is_unmute,
.can_send_other_messages = is_unmute,
.can_add_web_page_previews = is_unmute,
.can_change_info = is_unmute,
.can_invite_users = is_unmute,
.can_pin_messages = is_unmute
}
});
So, parameter until_date
will be used by telegram? It means telegram servers will unmute the user after that period of time and bot doesn't need to write the data in our database, right?
So, parameter until_date will be used by telegram?
Yes
It means telegram servers will unmute the user after that period of time and bot doesn't need to write the data in our database, right?
Yes, below is the explanation:
until_date
is date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever.
Okay, then I'll work on tmute
first.
@ALiwoto your work will be here https://github.com/GNUWeeb/GNUWeebBot/blob/2ba55c23b5fa9720d3b25bbb49080ddbeb506c91/src/gwbot/modules/003_admin/admin.c#L553-L567
For example, in that case, if an admin send a message: !tmute 2d 1h
, then the reason
variable will contain a pointer to 2d 1h
. You need to convert 2d 1h
to second unit (this will be until_date
), then pass it to do_mute()
.
Does that make sense to you?
@ALiwoto for the baseline, you can submit a simple parser code to me. I will co-author your name and email in the commit.
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <inttypes.h>
int main(void)
{
const char *reason = "2d 1h"; // 2 days 1 hour
time_t unix_time = 0;
/*
*
* Do something with the `reason` and `unix_time`
*
*/
printf("unix_time = %" PRIu64, (uint64_t)unix_time); // should print 176400 (2 days 1 hours in second unit)
}
Can you tell me what isADMIN_BITS
?
I can see the #define
part in here:
https://github.com/GNUWeeb/GNUWeebBot/blob/2ba55c23b5fa9720d3b25bbb49080ddbeb506c91/src/gwbot/modules/003_admin/admin.c#L40-L53
Can you explain it a bit?
@ammarfaizi2 Where should I put that simple parser? Can I write it in a separated file from repo and send it to you, or I should write it in tests directory?
Can you tell me what is ADMIN_BITS ?
@ALiwoto ADMIN_BITS
is a collection of bits that represents privileged commands (I should have added ADM_CMD_UNPIN
, I forgot).
So, you see the enum, range from (1u << 0u)
to (1u << 8u)
are commands for admin only. We can easily test whether a command needs to be executed by a privileged user or not with single bitwise AND
against ADMIN_BITS
.
@ammarfaizi2 Where should I put that simple parser? Can I write it in a separated file from repo and send it to you, or I should write it in tests directory?
You may post the code here (on the issue comment).
@ammarfaizi2
You may post the code here (on the issue comment).
Okay, I'll attach it to the next comment.
@ammarfaizi2 is delete message API related to this issue?
@komori-k yes, the !delvote
command, and we may add more commands that utilizes this API.
This bot needs to have group management features. So let's create it. In order to gets the bot working properly, the bot must be a group administrator with sufficient permissions.
Module Specification
!
or/
or.
or~
.!
, but you can use other prefixes mentioned above.Privileged commands
!ban
is a command for admin to ban a user (reply to user's message to be banned).!unban
is a command for admin to unban a user (reply to user's message to be unbanned).!kick
is a command for admin to kick a user (reply to user's message to be kicked). The difference with!ban
is that the kicked user is free to rejoin the group after they gets kicked. No unban action needs to be performed.!warn
is a command for admin to warn user (reply to user's message to be warned). The number of warnings will be stored in the bot database. When it reaches the maximum number, the warned user will be banned from the group.!mute
is a command for admin to mute user (reply to user's message to be muted).!tmute
is a command for admin to mute user temporarily. This command requires an argument. The argument is a number to determine how long the user is going to be muted. It can use suffixs
for second,m
for minute,d
for day,w
for week. By default, if suffix is not provided, then the unit will be second.!unmute
is a command for admin to unmute user (reply to user's message to be unmuted).!pin
is a command for admin to pin a message (reply to message to be pinned).!unpin
is a command for admin to unpin a message (reply to message to be unpinned).!del
or!delete
is a command for admin to delete a message (reply to message to be deleted).Normal user commands
!report
is a command for normal user to report an event to the admins. All admins will be notified via private message if they have started the bot.!delvote
is a command for normal user to vote a message deletion.Caveat: This document has not finished.