Code Monkey home page Code Monkey logo

Comments (12)

ALiwoto avatar ALiwoto commented on July 29, 2024

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?

from gnuweebbot.

ammarfaizi2 avatar ammarfaizi2 commented on July 29, 2024

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.

from gnuweebbot.

ALiwoto avatar ALiwoto commented on July 29, 2024

Okay, then I'll work on tmute first.

from gnuweebbot.

ammarfaizi2 avatar ammarfaizi2 commented on July 29, 2024

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

from gnuweebbot.

ammarfaizi2 avatar ammarfaizi2 commented on July 29, 2024

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

from gnuweebbot.

ALiwoto avatar ALiwoto commented on July 29, 2024

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?

from gnuweebbot.

ALiwoto avatar ALiwoto commented on July 29, 2024

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

from gnuweebbot.

ammarfaizi2 avatar ammarfaizi2 commented on July 29, 2024

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.

from gnuweebbot.

ammarfaizi2 avatar ammarfaizi2 commented on July 29, 2024

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

from gnuweebbot.

ALiwoto avatar ALiwoto commented on July 29, 2024

@ammarfaizi2

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

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

from gnuweebbot.

komori-k avatar komori-k commented on July 29, 2024

@ammarfaizi2 is delete message API related to this issue?

from gnuweebbot.

ammarfaizi2 avatar ammarfaizi2 commented on July 29, 2024

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

from gnuweebbot.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.