Skip to content

Group Allow List Commands

InJobBot can be added into groups and used by the owner or group admin to send jobs in chat or by group chat members (normal members) to view help and tips messages.

However, to prevent the abuse of the bot, it has a table in the database which is created on deployment or activation that has the list of groups id's that the bot is allowed to be added to.

If the bot was added to a group which is not in the database; it will leave.

Click to view the allow_list schema being created
persistence.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class UsersDatabase(IPersistenceLayer):
    """This class sits between the database commands and the database manger class"""

    def __init__(self) -> None:
        """_summary_ : This creates the 2 tables 'users' and 'allow_list'"""
        # Table name to be created if not existing
        self.table_name = "bot_users"
        # Initiating the data base users
        self.db = DatabaseManger("bot_db.sqlite")

        # Creating the table 'bot_users' in the database
        self.db.create_table(
            self.table_name,
            {
                # "id": "integer primary key autoincrement",
                "user_id": "text primary key not null",
                "block_type": "text not null",
                "date_added": "text not null",
            },
        )
        # Creating the allowlist table
        self.db.create_table(
            "allow_list",
            {
                "group_id": "text primary key not null",
            },
        )

This can be controlled by the bot's owner using the following commands.


Adding A Group To The List

The /addgroup command followed by the group chat id will add the group to the database. This command calls the execute() method on the the AddGroupToAllowListCommand(group_id) database command; adding the group to the allow_list table.

ljob_command
/addgroup command.

Click to view the AddGroupToAllowListCommand() database command class

Bases: ICommand

This command adds a group to the allow_list

Source code in src/database/db_commands.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
class AddGroupToAllowListCommand(ICommand):
    """This command adds a group to the allow_list"""

    def __init__(self, *, group_id: str) -> None:
        """_summary_ : This method gets the data to initiate the command to add group to the bot's allow list.

        Parameters
        ----------
        group_id : str
            _description_ : The group_id to allow.
        """
        self.group_id = group_id

    def execute(self) -> None:
        """This method adds group"""
        # Calling the add_to_allow_list with the group's chat_id.
        persistence.add_to_allow_list(self.group_id)
__init__(*, group_id: str) -> None

summary : This method gets the data to initiate the command to add group to the bot's allow list.

Parameters:

Name Type Description Default
group_id str

description : The group_id to allow.

required
Source code in src/database/db_commands.py
121
122
123
124
125
126
127
128
129
def __init__(self, *, group_id: str) -> None:
    """_summary_ : This method gets the data to initiate the command to add group to the bot's allow list.

    Parameters
    ----------
    group_id : str
        _description_ : The group_id to allow.
    """
    self.group_id = group_id
execute() -> None

This method adds group

Source code in src/database/db_commands.py
131
132
133
134
def execute(self) -> None:
    """This method adds group"""
    # Calling the add_to_allow_list with the group's chat_id.
    persistence.add_to_allow_list(self.group_id)

Removing A Group From The List

The /rmgroup command followed by the group chat id will remove the group from the database. This command calls the execute() method on the the DeleteGroupCommand(group_id) database command; removing the group from the allow_list table.

ljob_command
/rmgroup command.

Click to view the DeleteGroupCommand() database command class

Bases: ICommand

This command deletes Groups from the database.

Source code in src/database/db_commands.py
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
class DeleteGroupCommand(ICommand):
    """This command deletes Groups from the database."""

    def __init__(self, *, group_id: str) -> None:
        """_summary_ : This method gets the data to initiate the command to delete group from database.

        Parameters
        ----------
        group_id : str
            _description_ : Group's id.
        """
        self.group_id = group_id

    def execute(self):
        """This method deletes the user from the database using the provided criteria."""
        # Calling the delete_group method with the group's chat_id.
        persistence.delete_group(self.group_id)
__init__(*, group_id: str) -> None

summary : This method gets the data to initiate the command to delete group from database.

Parameters:

Name Type Description Default
group_id str

description : Group's id.

required
Source code in src/database/db_commands.py
164
165
166
167
168
169
170
171
172
def __init__(self, *, group_id: str) -> None:
    """_summary_ : This method gets the data to initiate the command to delete group from database.

    Parameters
    ----------
    group_id : str
        _description_ : Group's id.
    """
    self.group_id = group_id
execute()

This method deletes the user from the database using the provided criteria.

Source code in src/database/db_commands.py
174
175
176
177
def execute(self):
    """This method deletes the user from the database using the provided criteria."""
    # Calling the delete_group method with the group's chat_id.
    persistence.delete_group(self.group_id)

Getting Groups In The List

The /getgroups command will list all the groups in the database. This command calls the execute() method on the the GetGroupCommand(group_id) database command; listing all the groups in the allow_list table.

Note

Following the /getgroups command by the group chat id; will return the group id back if it exists in the database.

ljob_command
/getgroup command.

Click to view the GetGroupCommand() database command class

Bases: ICommand

This command sends a 'SELECT' query to the allow_list database returning with group in it.

Source code in src/database/db_commands.py
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
class GetGroupCommand(ICommand):
    """This command sends a 'SELECT' query to the allow_list database returning with group in it."""

    def __init__(self, *, group_id: str = None, order_by="date_added") -> None:
        """_summary_ : This method gets the data to initiate the command to get user from database using group_id as a selection criteria and sort the results back using 'date_added' attribute (columns).

        Parameters
        ----------
        group_id : str
            _description_ : group_id.
        order_by : str, optional
            _description_, by default "date_added" : The criteria in which to sort the returned query results.
        """
        # Setting the order_by criteria. By default will sort by date_added
        self.order_by = order_by
        # Setting the user's group_id
        self.group_id = group_id

    def execute(self) -> list:
        """This method executes the 'SELECT' statement."""
        # Calling the get_group method with the group's chat_id.
        return persistence.get_group(group_id=self.group_id)
__init__(*, group_id: str = None, order_by: str = 'date_added') -> None

summary : This method gets the data to initiate the command to get user from database using group_id as a selection criteria and sort the results back using 'date_added' attribute (columns).

Parameters:

Name Type Description Default
group_id str

description : group_id.

None
order_by str

description, by default "date_added" : The criteria in which to sort the returned query results.

'date_added'
Source code in src/database/db_commands.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
def __init__(self, *, group_id: str = None, order_by="date_added") -> None:
    """_summary_ : This method gets the data to initiate the command to get user from database using group_id as a selection criteria and sort the results back using 'date_added' attribute (columns).

    Parameters
    ----------
    group_id : str
        _description_ : group_id.
    order_by : str, optional
        _description_, by default "date_added" : The criteria in which to sort the returned query results.
    """
    # Setting the order_by criteria. By default will sort by date_added
    self.order_by = order_by
    # Setting the user's group_id
    self.group_id = group_id
execute() -> list

This method executes the 'SELECT' statement.

Source code in src/database/db_commands.py
155
156
157
158
def execute(self) -> list:
    """This method executes the 'SELECT' statement."""
    # Calling the get_group method with the group's chat_id.
    return persistence.get_group(group_id=self.group_id)