def test_is_not_valid_message_malformed_message(): message = FakeMessage("@Chess2GIF malformed message") user = discord.ClientUser(state={}, data=USER_DATA) bot = discord.ClientUser(state={}, data=BOT_USER_DATA) message.mentions = [bot] message.author = user check, error = is_valid_message(message, bot_user=bot) assert check is False error is not None
def test_is_valid_message(): message = FakeMessage("@Chess2GIF player:hikaru") user = discord.ClientUser(state={}, data=USER_DATA) bot = discord.ClientUser(state={}, data=BOT_USER_DATA) message.mentions = [bot] message.author = user check, error = is_valid_message(message, bot_user=bot) assert check is True error is None
def __init__(self, client, http, user=None, loop=None): if loop is None: loop = asyncio.get_event_loop() super().__init__(dispatch=client.dispatch, handlers=None, hooks=None, syncer=None, http=http, loop=loop) if user is None: user = discord.ClientUser(state=self, data=facts.make_user_dict( "FakeApp", "0001", None)) self.user = user self.shard_count = client.shard_count self._get_websocket = lambda x: client.ws self._do_dispatch = True real_disp = self.dispatch def dispatch(*args, **kwargs): if not self._do_dispatch: return return real_disp(*args, **kwargs) self.dispatch = dispatch
def __init__(self, client: discord.Client, http: dhttp.HTTPClient, user: discord.ClientUser = None, loop: asyncio.AbstractEventLoop = None) -> None: if loop is None: loop = asyncio.get_event_loop() super().__init__( dispatch=client.dispatch, handlers=None, hooks=None, syncer=None, http=http, loop=loop, intents=client.intents, member_cache_flags=client._connection.member_cache_flags) if user is None: user = discord.ClientUser(state=self, data=facts.make_user_dict( "FakeApp", "0001", None)) user.bot = True self.user = user self.shard_count = client.shard_count self._get_websocket = lambda x: client.ws self._do_dispatch = True real_disp = self.dispatch def dispatch(*args, **kwargs): if not self._do_dispatch: return return real_disp(*args, **kwargs) self.dispatch = dispatch
def test_is_not_valid_message_by_bot(): """If the bot wrote the message, we should ignore it""" bot = discord.ClientUser(state={}, data=BOT_USER_DATA) message = FakeMessage("@Chess2GIF player:hikaru") message.mentions = [bot] message.author = bot check, error = is_valid_message(message, bot_user=bot) assert check is False error is None
async def main(): config = config_from_file("config.yaml") assert config.get("pg_credentials") assert config.get("pg_credentials") == config.pg_credentials db = await asyncpg.create_pool(**config.pg_credentials) intents = discord.Intents( guilds=True, emojis=True, guild_messages=True, guild_reactions=True, message_content=True, ) session = aiohttp.ClientSession() bot = Queuebot(command_prefix='q!', intents=intents, config=config, db=db, session=session) await bot.discover_exts('queuebot/cogs') # imaginary login bot._connection.user = discord.ClientUser(state=bot._connection, data={ "username": "******", "id": "210987654321098765", "discriminator": '1337', "avatar": None, "bot": True }) record = await bot.db.fetchrow( """ INSERT INTO suggestions ( user_id, council_message_id, emoji_id, emoji_name, submission_time, suggestions_message_id, emoji_animated ) VALUES ( $1, $2, $3, $4, $5, $6, $7 ) RETURNING idx """, 122122926760656896, 294924538062569492, 396521731440771085, "blobsmile", datetime.datetime.utcnow(), 312640412474933248, False) idx = record["idx"] assert idx from queuebot.cogs.queue.suggestion import Suggestion suggestion = await Suggestion.get_from_id(idx) assert repr(suggestion) == \ f"<Suggestion idx={idx} user_id=122122926760656896 upvotes=0 downvotes=0>" queuecog = bot.get_cog("BlobQueue") approve_name, approve_id = config.approve_emoji.split(':') event = raw_models.RawReactionActionEvent( { 'message_id': 294924538062569492, 'channel_id': config.council_queue, 'user_id': 69198249432449024, }, discord.PartialEmoji(animated=False, name=approve_name, id=int(approve_id)), 'REACTION_ADD', ) await queuecog.on_raw_reaction_add(event) await suggestion.update_inplace() assert repr(suggestion) == \ f"<Suggestion idx={idx} user_id=122122926760656896 upvotes=1 downvotes=0>" await bot.close()