Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[module] Admin module for group management #20

Open
ammarfaizi2 opened this issue May 2, 2021 · 12 comments
Open

[module] Admin module for group management #20

ammarfaizi2 opened this issue May 2, 2021 · 12 comments
Assignees
Labels
documentation Improvements or additions to documentation module This issue has something todo with bot module

Comments

@ammarfaizi2
Copy link
Contributor

ammarfaizi2 commented May 2, 2021

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

  • Command in this module is any message that starts with ! or / or . or ~.
  • In this document, we will demonstrate any command starts with !, but you can use other prefixes mentioned above.

Privileged commands

  1. !ban is a command for admin to ban a user (reply to user's message to be banned).
  2. !unban is a command for admin to unban a user (reply to user's message to be unbanned).
  3. !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.
  4. !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.
  5. !mute is a command for admin to mute user (reply to user's message to be muted).
  6. !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 suffix s for second, m for minute, d for day, w for week. By default, if suffix is not provided, then the unit will be second.
  7. !unmute is a command for admin to unmute user (reply to user's message to be unmuted).
  8. !pin is a command for admin to pin a message (reply to message to be pinned).
  9. !unpin is a command for admin to unpin a message (reply to message to be unpinned).
  10. !del or !delete is a command for admin to delete a message (reply to message to be deleted).

Normal user commands

  1. !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.
  2. !delvote is a command for normal user to vote a message deletion.

Caveat: This document has not finished.

@ammarfaizi2 ammarfaizi2 added documentation Improvements or additions to documentation module This issue has something todo with bot module labels May 2, 2021
@ammarfaizi2 ammarfaizi2 self-assigned this May 2, 2021
@ALiwoto
Copy link
Member

ALiwoto commented May 5, 2021

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?

@ammarfaizi2
Copy link
Contributor Author

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.

@ALiwoto
Copy link
Member

ALiwoto commented May 5, 2021

Okay, then I'll work on tmute first.

@ammarfaizi2
Copy link
Contributor Author

@ALiwoto your work will be here

run_module:
if (reply_to == NULL) {
if (reason == NULL) {
// target_uid = ???
goto out;
}
/*
* TODO: Parse the reason, it may contain
* username, user_id, etc.
*/
goto out;
} else {

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?

@ammarfaizi2
Copy link
Contributor Author

ammarfaizi2 commented May 5, 2021

@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)
}

@ALiwoto
Copy link
Member

ALiwoto commented May 5, 2021

Can you tell me what isADMIN_BITS ?

I can see the #define part in here:

#define ADMIN_BITS \
( \
ADM_CMD_BAN | \
ADM_CMD_UNBAN | \
ADM_CMD_KICK | \
ADM_CMD_WARN | \
ADM_CMD_MUTE | \
ADM_CMD_TMUTE | \
ADM_CMD_UNMUTE | \
ADM_CMD_PIN \
)

Can you explain it a bit?

@ALiwoto
Copy link
Member

ALiwoto commented May 5, 2021

@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?

@ammarfaizi2
Copy link
Contributor Author

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
Copy link
Contributor Author

@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).

@ALiwoto
Copy link
Member

ALiwoto commented May 5, 2021

@ammarfaizi2

You may post the code here (on the issue comment).

Okay, I'll attach it to the next comment.

@komori-k
Copy link
Contributor

@ammarfaizi2 is delete message API related to this issue?

@ammarfaizi2
Copy link
Contributor Author

@komori-k yes, the !delvote command, and we may add more commands that utilizes this API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation module This issue has something todo with bot module
Projects
None yet
Development

No branches or pull requests

3 participants