Exemplo n.º 1
0
async def on_ready():
    bot.owner = await bot.fetch_user(SETTINGS.owner_id)

    mongo = AsyncIOMotorClient(SETTINGS.mongo_db)
    bot.db = mongo.pollmaster
    bot.session = aiohttp.ClientSession()
    print(bot.db)

    # check discord server configs
    try:
        db_server_ids = [
            entry['_id'] async for entry in bot.db.config.find({}, {})
        ]
        for server in bot.guilds:
            if str(server.id) not in db_server_ids:
                # create new config entry
                await bot.db.config.update_one({'_id': str(server.id)}, {
                    '$set': {
                        'prefix': 'pm!',
                        'admin_role': 'polladmin',
                        'user_role': 'polluser'
                    }
                },
                                               upsert=True)

    except:
        print("Problem verifying servers.")

    # cache prefixes
    bot.pre = {
        entry['_id']: entry['prefix']
        async for entry in bot.db.config.find({}, {'_id', 'prefix'})
    }

    bot.locks = {}
    bot.message_cache = MessageCache(bot)

    game = discord.Game("Democracy 4")
    await bot.change_presence(status=discord.Status.online, activity=game)

    print("Servers verified. Bot running.")
Exemplo n.º 2
0
    def __init__(self, **kwargs):
        self.pipe = kwargs.pop('pipe')
        self.cluster_name = kwargs.pop('cluster_name')
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        super().__init__(**kwargs, loop=loop)
        self.websocket = None
        self._last_result = None
        self.ws_task = None
        self.responses = asyncio.Queue()
        self.eval_wait = False
        log = logging.getLogger(f"Cluster#{self.cluster_name}")
        log.setLevel(logging.DEBUG)
        log.handlers = [logging.FileHandler(f'cluster-{self.cluster_name}.log', encoding='utf-8', mode='a')]

        log.info(f'[Cluster#{self.cluster_name}] {kwargs["shard_ids"]}, {kwargs["shard_count"]}')
        self.log = log

        self.owner = None
        self.db = None
        self.session = None
        self.emoji_dict = None
        self.pre = None

        self.remove_command('help')
        self.load_extension("cogs.eval")
        extensions = ['cogs.config', 'cogs.poll_controls', 'cogs.help', 'cogs.db_api', 'cogs.admin']
        for ext in extensions:
            self.load_extension(ext)

        self.message_cache = MessageCache(self)
        self.refresh_blocked = {}
        self.refresh_queue = {}

        self.loop.create_task(self.ensure_ipc())
        self.run(kwargs['token'])
Exemplo n.º 3
0
from essentials.settings import SETTINGS

bot_config = {
    'command_prefix': get_pre,
    'case_insensitive': True,
    'pm_help': False,
    'status': discord.Status.online,
    'owner_id': SETTINGS.owner_id,
    'fetch_offline_members': False,
    'max_messages': 15000
}

bot = commands.AutoShardedBot(**bot_config)
bot.remove_command('help')

bot.message_cache = MessageCache(bot)
bot.refresh_blocked = {}
bot.refresh_queue = {}

# logger
# create logger with 'spam_application'
logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
# create file handler which logs even debug messages
fh = logging.FileHandler('pollmaster.log', encoding='utf-8', mode='w')
fh.setLevel(logging.INFO)
# create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.ERROR)
# create formatter and add it to the handlers
formatter = logging.Formatter(
Exemplo n.º 4
0
from commands import *
from commands.assign import *
from commands.task import *
from essentials.messagecache import MessageCache
from essentials.multi_server import ask_for_server

intents = discord.Intents.default()
intents.members = True

client = commands.Bot(command_prefix="/task ", intents=intents)
mydbcursor = None
logger = logging.getLogger('discord')

extensions = ['essentials.notifications']

client.message_cache = MessageCache(client)


@client.event
async def on_ready():
    # mongodb below

    mongo = AsyncIOMotorClient(SETTINGS.mongo_db)
    client.db = mongo.taskmaster
    client.session = aiohttp.ClientSession()
    print(client.db)
    try:
        db_server_ids = [
            entry['_id'] async for entry in client.db.config.find({}, {})
        ]
        for server in client.guilds: