def __init__(self): super().__init__() self.ready = False # State attributes before initialization. self.log = None self.cfg = None self.db = None self.cool_down = None self.music = None self.modules = None self.queue = ExecutionClockwork(self) self.cache = Cacher() # Initialize startup methods and attributes. self.create_cache() self.init_logger() self.log.info('---------------------------------') self.init_config() self.log.info('---------------------------------') self.loop.run_until_complete(self.init_database()) self.log.info('---------------------------------') self.init_cool_down() self.log.info('---------------------------------') self.init_music() self.log.info('---------------------------------') self.info = Information() self.init_modules(init=True) self.start_time = arrow.utcnow() self.message_count = 0 self.command_count = 0
def __init__(self, bot, db_cfg: DatabaseConfig): self.bot = bot self.db_cfg = db_cfg self.cache = Cacher() if self.db_cfg.auth: self.db_address = f'mongodb://{self.db_cfg.username}:{self.db_cfg.password}' self.db_address += f'@{self.db_cfg.host}:{self.db_cfg.port}/' else: self.db_address = f'mongodb://{self.db_cfg.host}:{self.db_cfg.port}/' super().__init__(self.db_address)
def test_setter(self): cache = Cacher() pairs = {} for _ in range(test_count): random_key = self.get_random_generator()() random_val = self.get_random_generator()() cache.set_cache(random_key, random_val) pairs.update({random_key: random_val}) for pair in pairs.keys(): assert cache.get_cache(pair) == pairs.get(pair)
def test_deleter(self): cache = Cacher() keys = [] for _ in range(test_count): random_key = self.get_random_generator()() random_val = self.get_random_generator()() cache.set_cache(random_key, random_val) keys.append(random_key) for key in keys: cache.del_cache(key) assert cache.get_cache(key) is None assert cache.data == {}
# This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from sigma.core.mechanics.caching import Cacher perm_cache = Cacher() def generate_default_data(message): return { 'server_id': message.guild.id, 'disabled_commands': [], 'disabled_modules': [], 'command_exceptions': {}, 'module_exceptions': {}, } def generate_cmd_data(cmd_name): return {cmd_name: {'users': [], 'channels': [], 'roles': []}}
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import arrow import discord from humanfriendly.tables import format_pretty_table as boop from sigma.core.mechanics.caching import Cacher from sigma.core.mechanics.command import SigmaCommand from sigma.modules.moderation.server_settings.filters.name_check_clockwork import clean_name txplb_cache = Cacher() async def topexperience(cmd: SigmaCommand, message: discord.Message, args: list): value_name = 'Experience' sort_key = 'global' lb_category = 'Global' search = {} if args: if args[0].lower() == 'local': sort_key = f'guilds.{message.guild.id}' search = {sort_key: {'$exists': True}} lb_category = message.guild.name elif args[0].lower() == 'total': sort_key = 'total'
def __init__(self, bot): self.bot = bot self.db = self.bot.db self.cache = Cacher() self.cds = self.db[self.bot.cfg.db.database].CooldownSystem
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import asyncio import discord from sigma.core.mechanics.caching import Cacher gcp_cache = Cacher() scp_cache = Cacher() class GlobalCommandPermissions(object): def __init__(self, command, message: discord.Message): self.message = message self.bot = command.bot self.cmd = command self.db = command.db self.loop = asyncio.get_event_loop() # Default States self.nsfw_denied = False self.black_user = False self.black_srv = False self.owner_denied = False
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import discord from humanfriendly.tables import format_pretty_table as boop from sigma.core.mechanics.caching import Cacher from sigma.core.mechanics.command import SigmaCommand from sigma.core.utilities.data_processing import get_image_colors from sigma.modules.moderation.server_settings.filters.name_check_clockwork import clean_name tck_cache = Cacher(True, 3600) async def topcookies(cmd: SigmaCommand, message: discord.Message, args: list): value_name = 'Cookies' sort_key = 'Cookies' lb_icon = cmd.bot.user.avatar_url lb_category = 'Global' localed = False if args: if args[0].lower() == 'total': sort_key = 'Total' lb_category = 'Total' elif args[0].lower() == 'local': lb_category = 'Local' lb_icon = message.guild.icon_url or lb_icon
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import discord from humanfriendly.tables import format_pretty_table as boop from sigma.core.mechanics.caching import Cacher from sigma.core.mechanics.command import SigmaCommand from sigma.core.utilities.data_processing import get_image_colors from sigma.modules.moderation.server_settings.filters.name_check_clockwork import clean_name tcr_cache = Cacher(True, 3600) async def topcurrency(cmd: SigmaCommand, message: discord.Message, args: list): value_name = cmd.bot.cfg.pref.currency sort_key = 'global' lb_icon = cmd.bot.user.avatar_url lb_category = 'Global' search = {} if args: if args[0].lower() == 'local': sort_key = f'guilds.{message.guild.id}' search = {sort_key: {'$exists': True}} lb_icon = message.guild.icon_url or lb_icon lb_category = message.guild.name elif args[0].lower() == 'total':
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import arrow import discord from humanfriendly.tables import format_pretty_table as boop from sigma.core.mechanics.caching import Cacher from sigma.core.mechanics.command import SigmaCommand from sigma.modules.moderation.server_settings.filters.edit_name_check import clean_name tcrlb_cache = Cacher() async def topcurrency(cmd: SigmaCommand, message: discord.Message, args: list): value_name = cmd.bot.cfg.pref.currency sort_key = 'global' lb_category = 'Global' search = {} if args: if args[0].lower() == 'local': sort_key = f'guilds.{message.guild.id}' search = {sort_key: {'$exists': True}} lb_category = message.guild.name elif args[0].lower() == 'total': sort_key = 'total' lb_category = 'Total'
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import asyncio import arrow import discord from sigma.core.mechanics.caching import Cacher from sigma.core.mechanics.event import SigmaEvent decay_clock_running = False decay_cache = Cacher() async def decay_checker(ev: SigmaEvent): global decay_clock_running if not decay_clock_running: decay_clock_running = True ev.bot.loop.create_task(decay_checker_clock(ev)) async def decay_checker_clock(ev: SigmaEvent): while True: if ev.bot.is_ready(): try: now = arrow.utcnow().timestamp dmsgs = decay_cache.get_cache('all')
def __init__(self, bot): self.bot = bot self.db = self.bot.db self.cache = Cacher() self.cds = self.db[self.db.db_nam].CooldownSystem
# GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import functools from concurrent.futures import ThreadPoolExecutor import discord import markovify from sigma.core.mechanics.caching import Cacher from sigma.core.mechanics.command import SigmaCommand from sigma.core.utilities.data_processing import user_avatar chain_object_cache = Cacher(True, 300) async def impersonate(cmd: SigmaCommand, message: discord.Message, args: list): if args: if message.mentions: target = message.mentions[0] else: target = discord.utils.find( lambda x: x.name.lower() == ' '.join(args).lower(), message.guild.members) else: target = message.author if target: chain_data = await cmd.db[cmd.db.db_cfg.database ]['MarkovChains'].find_one(
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import arrow import discord from sigma.core.mechanics.caching import Cacher from sigma.core.mechanics.command import SigmaCommand afk_cache = Cacher() async def afk(cmd: SigmaCommand, message: discord.Message, args: list): afk_data = afk_cache.get_cache(message.author.id) if not afk_data: afk_data = await cmd.db[cmd.db.db_nam].AwayUsers.find_one( {'user_id': message.author.id}) if args: afk_reason = ' '.join(args) else: afk_reason = 'No reason stated.' in_data = { 'user_id': message.author.id, 'timestamp': arrow.utcnow().timestamp, 'reason': afk_reason
def test_getter(self): cache = Cacher() assert cache.get_cache(self.get_random_generator()()) is None
# GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import functools from concurrent.futures import ThreadPoolExecutor import discord import markovify from sigma.core.mechanics.caching import Cacher from sigma.core.mechanics.command import SigmaCommand from sigma.core.utilities.data_processing import user_avatar chain_object_cache = Cacher() async def impersonate(cmd: SigmaCommand, message: discord.Message, args: list): if args: if message.mentions: target = message.mentions[0] else: target = discord.utils.find( lambda x: x.name.lower() == ' '.join(args).lower(), message.guild.members) else: target = message.author if target: chain_data = await cmd.db[cmd.db.db_nam].MarkovChains.find_one( {'user_id': target.id})
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import functools import secrets from concurrent.futures import ThreadPoolExecutor import discord import markovify from sigma.core.mechanics.caching import Cacher from sigma.core.mechanics.command import SigmaCommand from sigma.core.utilities.data_processing import user_avatar from sigma.modules.utilities.mathematics.impersonate import chain_object_cache combination_cache = Cacher() def combine_names(user_one, user_two): cutoff_one = len(user_one.name) // 2 cutoff_two = len(user_two.name) // 2 piece_one = user_one.name[:cutoff_one] piece_two = user_two.name[cutoff_two:] output = piece_one + piece_two return output async def combinechains(cmd: SigmaCommand, message: discord.Message, args: list): if len(message.mentions) == 2: target_one = message.mentions[0]
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import arrow import discord from humanfriendly.tables import format_pretty_table as boop from sigma.core.mechanics.caching import Cacher from sigma.core.mechanics.command import SigmaCommand from sigma.modules.moderation.server_settings.filters.name_check_clockwork import clean_name tcklb_cache = Cacher() async def topcookies(cmd: SigmaCommand, message: discord.Message, args: list): value_name = 'Cookies' sort_key = 'Cookies' lb_category = 'Global' localed = False if args: if args[0].lower() == 'total': sort_key = 'Total' lb_category = 'Total' elif args[0].lower() == 'local': lb_category = 'Local' localed = True cache_key = message.guild.id if localed else sort_key
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import discord from humanfriendly.tables import format_pretty_table as boop from sigma.core.mechanics.caching import Cacher from sigma.core.mechanics.command import SigmaCommand from sigma.core.utilities.data_processing import get_image_colors from sigma.modules.moderation.server_settings.filters.name_check_clockwork import clean_name txp_cache = Cacher(True, 3600) async def topexperience(cmd: SigmaCommand, message: discord.Message, args: list): value_name = 'Experience' sort_key = 'global' lb_icon = cmd.bot.user.avatar_url lb_category = 'Global' search = {} if args: if args[0].lower() == 'local': sort_key = f'guilds.{message.guild.id}' search = {sort_key: {'$exists': True}} lb_icon = message.guild.icon_url or lb_icon lb_category = message.guild.name