Example #1
0
    async def mod_cmd_tracker_db_clear(self, ctx: commands.Context, code: str = ""):
        if self.loaded is False:
            return

        confirm_manager = self.ukparl_module.confirm_manager

        if confirm_manager.has_code(ctx.author):
            if code == "":
                return await embed_maker.message(
                    ctx,
                    description="Confirm code required to execute this command successfully.",
                    send=True,
                )
            if confirm_manager.confirm_code(ctx.author, code):
                database.get_connection().clear_bills_tracker_collection()
                database.get_connection().clear_divisions_tracker_collection()
                return await embed_maker.message(
                    ctx,
                    description="Cleared bills_tracker and division_tracker collections.",
                    send=True,
                )
            else:
                return await embed_maker.message(
                    ctx, description="Confirm code incorrect.", send=True
                )
        code = confirm_manager.gen_code(ctx.author)
        await embed_maker.message(
            ctx,
            description="Sending confirmation to delete contents of 'bills_tracker' and 'divisions_tracker'.",
            send=True,
        )
        await ctx.author.send(f"Code to confirm clear Mongo Collections: {code}")
Example #2
0
    async def add_division(self, division: Union[LordsDivision, CommonsDivision]):
        """
        Add a division to the collection. A non-bill division is a division that is
        not related to a bill.

        Parameters
        ----------
        divsion: :class:`Union[LordsDivision, CommonsDivision]`
            A commons or lords division.
        """
        database.get_connection().add_division(division)
Example #3
0
    async def add_feed_update(self, bill_id: int, update: FeedUpdate):
        """
        Add a feed update.

        Parameters
        ----------
        bill_id: :class:`int`
            The id of the bill related to the feed update.
        update: :class:`FeedUpdate`
            The feed update.
        """
        database.get_connection().add_bill_feed_update(bill_id, update)
Example #4
0
    async def add_bill_division(
        self, bill_id: int, division: Union[LordsDivision, CommonsDivision]
    ):
        """
        Add a bill division. Bill divisions are divisions relating to a bill.

        Parameters
        ----------
        bill_id: :class:`int`
            A bill id
        division: :class:`Union[LordsDivision, CommonsDivision]`
            A commons or lords division.
        """
        database.get_connection().add_bill_division(bill_id, division)
    def __init__(self, guild_id: int):
        """
        Utility/handler class to interface with the collection containing the channel ids for each tracker.
        Used soley to store the ids of channel assigned to each tracker.
        """
        self.db = database.get_connection()
        self.settings = self.db.get_guild_settings(guild_id)
        self.guild_id = guild_id
        if "modules" not in self.settings.keys():
            self.db.guild_settings.update_one(
                {"guild_id": guild_id}, {"$set": {"modules": {}}}
            )
            self.settings = self.db.get_guild_settings(guild_id)

        if "ukparliament" not in self.settings["modules"].keys():
            self.db.guild_settings.update_one(
                {"guild_id": guild_id},
                {
                    "$set": {
                        "modules": {
                            "ukparliament": {
                                "royal_assent": 0,
                                "lords_divisions": 0,
                                "commons_divisions": 0,
                                "publications": 0,
                                "feed": 0,
                            }
                        }
                    }
                },
            )
            self.settings = self.db.get_guild_settings(guild_id)
Example #6
0
    async def division_stored(self, division: Union[LordsDivision, CommonsDivision]):
        """
        Check if a non-bill division has been stored.

        Parameters
        ----------
        division: :class:`Union[LordsDivision, CommonsDivision]`
            A commons or lords division.
        """
        return database.get_connection().is_division_stored(division)
Example #7
0
    async def bill_division_stored(
        self, bill_id: int, division: Union[LordsDivision, CommonsDivision]
    ):
        """
        Check if a bill division is stored.

        Parameters
        ----------
        bill_id: :class:`int`
            The bill id
        division: :class:`Union[LordsDivision, CommonsDivision]`
            A commons or lords division
        """
        return database.get_connection().is_bill_division_stored(bill_id, division)
Example #8
0
    async def get_last_update(self, bill_id: int):
        """
        Gets the most recent update to be stored in relation to the bill_id.

        Parameters
        ---------
        bill_id: :class:`int`
            The id of the bill.

        Returns
        -------
        :class: `Union[object, None]`
            A dictionary object with three keys: bill_id, timestamp, and stage. Or nothing.
        """
        return database.get_connection().get_bill_last_update(bill_id)
Example #9
0
    async def has_update_stored(self, bill_id: int, update: FeedUpdate):
        """
        Check if an update has been stored.

        Parameters
        ----------
        bill_id: :class:`int`
            The id of the bill related to the feed update.
        update: :class:`FeedUpdate`
            The feed update.

        Returns
        -------
        :class:`bool`
            True if the update has been stored else False
        """
        return database.get_connection().is_bill_update_stored(bill_id, update)
Example #10
0
    async def get_bill_divisions(self, bill_id: int):
        """
        Fetch all bill divisions.

        Parameters
        ----------
        bill_id: :class:`int`
            The bill id

        Returns
        -------
        :class:`list`
            A list of dictionaries with the following keys:
            'bill_id': the id of the bill
            'division_id': the id of the division
            'timestamp': the timestamp of the division
        """
        return database.get_connection().get_bill_divisions(bill_id)
Example #11
0
    def __init__(self, settings_handler: SettingsHandler, guild_id: int):
        """
        Utility/handler class to interface with the collection containing the channel ids for each tracker.
        Used soley to store the ids of channel assigned to each tracker.
        """
        self._settings_handler: SettingsHandler = settings_handler
        self.db = database.get_connection()
        settings = self._settings_handler.get_settings(guild_id)
        self.guild_id = guild_id

        if "ukparliament" not in settings["modules"].keys():
            settings["modules"]["ukparliament"] = {
                "royal_assent": 0,
                "lords_divisions": 0,
                "commons_divisions": 0,
                "publications": 0,
                "feed": 0,
            }
            self._settings_handler.save(settings)
Example #12
0
import math
import datetime
import functools
import re
from bot import TLDR
from modules.utils import (
    ParseArgs,
    get_member,
    get_member_from_string
)
from typing import Union, Optional
from modules import embed_maker, commands, database, format_time, leveling
from random import randint
from discord.ext.commands import Cog, command, Context, group
from modules.reaction_menus import BookMenu
db = database.get_connection()


class Cooldown:
    def __init__(self, cooldown_in_seconds: int = 60):
        self.cooldown_in_seconds = cooldown_in_seconds
        self.cooldown_users = {}

    def add_user(self, guild_id: int, user_id: int):
        if guild_id not in self.cooldown_users:
            self.cooldown_users[guild_id] = {}

        now = time.time() + self.cooldown_in_seconds
        self.cooldown_users[guild_id][user_id] = now

    def user_cooldown(self, guild_id: int, user_id: int) -> int:
Example #13
0
 def __init__(self):
     self._db = database.get_connection()
     self._settings = {}