Ejemplo n.º 1
0
    async def _send_error(self, message):

        # Hey, if you've stumbled upon this, you might be asking:
        # "Xua, why are you instantiating your own DMChannel?"
        # My answer: no idea
        # I could save the stupidness and just use get_user.dm_channel
        # But what if an error happens pre on_ready?
        # The user might not be cached.

        # Of course, this wouldn't technically matter if the webhook exists,
        # but webhooks are optional so :rooShrug:

        if isinstance(config.DEBUG_WEBHOOK, str):
            if config.DEBUG_WEBHOOK:
                self.debug_hook = discord.Webhook.from_url(config.DEBUG_WEBHOOK,
                                                           adapter=discord.AsyncWebhookAdapter(self.session))
            else:
                data = await self.http.start_private_message(config.OWNERS[0])
                self.debug_hook = discord.DMChannel(me=self.user, state=self._connection, data=data)

        if isinstance(message, str) and len(message) > 2000:
            async with self.session.post("https://mystb.in/documents", data=message.encode()) as post:
                if post.status == 200:
                    data = await post.json()
                    return await self._send_error(f"Error too long: https://mystb.in/{data['key']}")

                # no mystbin, fallback to files
                file = io.BytesIO(message.encode())
                return await self._send_error(discord.File(file, "error.txt"))
        elif isinstance(message, discord.File):
            await self.debug_hook.send(message)
        else:
            await self.debug_hook.send(message)
Ejemplo n.º 2
0
            'id': next(self.discord_id),
            'name': 'channel',
            'guild': MockGuild()
        }
        super().__init__(**collections.ChainMap(kwargs, default_kwargs))

        if 'mention' not in kwargs:
            self.mention = f"#{self.name}"


# Create data for the DMChannel instance
state = unittest.mock.MagicMock()
me = unittest.mock.MagicMock()
dm_channel_data = {"id": 1, "recipients": [unittest.mock.MagicMock()]}
dm_channel_instance = discord.DMChannel(me=me,
                                        state=state,
                                        data=dm_channel_data)


class MockDMChannel(CustomMockMixin, unittest.mock.Mock, HashableMixin):
    """
    A MagicMock subclass to mock TextChannel objects.

    Instances of this class will follow the specifications of `discord.TextChannel` instances. For
    more information, see the `MockGuild` docstring.
    """
    spec_set = dm_channel_instance

    def __init__(self, **kwargs) -> None:
        default_kwargs = {
            'id': next(self.discord_id),
Ejemplo n.º 3
0
    ):
        channel_id = int(data["value"])
        resolved_channel = resolved["channels"][data["value"]]
        if self.guild_id:
            if channel := self.guild.get_channel(channel_id):
                pass
            else:
                channel = discord.TextChannel(
                    state=self._state, guild=self.guild, data=resolved_channel
                )
        else:
            if channel := self._state._get_private_channel(channel_id):
                pass
            else:
                channel = discord.DMChannel(
                    state=self._state, me=self.bot.user, data=resolved_channel
                )
        option.set_value(channel)
        return option

    def _handle_option_user(
        self, data: dict, option: ResponseOption, resolved: Dict[str, Dict[str, dict]]
    ):
        user_id = int(data["value"])
        resolved_user = resolved["users"][data["value"]]
        if self.guild_id:
            if user := self.guild.get_member(user_id):
                pass
            else:
                user = discord.Member(guild=self.guild, data=resolved_user, state=self._state)
                self.guild._add_member(user)
Ejemplo n.º 4
0
# https://github.com/Tyrrrz/DiscordChatExporter/wiki/Obtaining-Token-and-Channel-IDs#how-to-get-a-user-token

from secrets import USER_TOKEN

DISCORD_BOT = "BYOCTF_Automaton#7840"


client = discord.Client()
client.start()

client.login(USER_TOKEN, bot=False)
client.user.id

byoctf_bot = discord.C

dmchan = discord.DMChannel()

def sendMessage(msg):
    return f'sent message {msg}'

class Commands(discord.Client):
    def sub(self,  flag):
        # print(f"ctx {ctx} ")
        resp = sendMessage(f"!sub {flag}")
        print(resp)

    def solves(self):
        resp = sendMessage(f"!solves")
        print(resp)

if __name__ == '__main__':
Ejemplo n.º 5
0
# -*- coding: utf8 -*-

data = "<Message id=718820557692600341 channel=<DMChannel id=718416701603053659 recipient=<User id=194426461229285376 name='Жидков Артемий' discriminator='4076' bot=False>> type=<MessageType.default: 0> author=<User id=194426461229285376 name='Жидков Артемий' discriminator='4076' bot=False> flags=<MessageFlags value=0>>"

import discord

msg = discord.Message()
msg.channel = discord.DMChannel()