Ejemplo n.º 1
0
async def on_message(data, shard):
    if len(data.get("sticker_items", [])) != 0:
        r = Route("DELETE",
                  "/channels/{channel_id}/messages/{message_id}",
                  channel_id=data["channel_id"],
                  message_id=data["id"])
        await client.http.request(r)
        r = Route("POST",
                  "/channels/{channel_id}/messages",
                  channel_id=data["channel_id"])
        await client.http.request(
            r,
            json={
                "content":
                f"Yoo you dumbass stop using the sticker or I'll hack you <@{data['author']['id']}>"
            })
Ejemplo n.º 2
0
async def on_message(data, shard):
    if len(data.get("stickers", [])) != 0:
        r = Route("DELETE",
                  "/channels/{channel_id}/messages/{message_id}",
                  channel_id=data["channel_id"],
                  message_id=data["id"])
        await client.http.request(r)
        r = Route("POST",
                  "/channels/{channel_id}/messages",
                  channel_id=data["channel_id"])
        await client.http.request(
            r,
            json={
                "content":
                f"Shut up <@{data['author']['id']}> you are literally canadian 🇨🇦"
            })
Ejemplo n.º 3
0
async def on_message(data, shard):
    message = data
    if message["content"].lower() == "!test":
        channel = message["channel_id"]
        route = Route("POST",
                      f"/channels/{channel}/messages",
                      channel_id=channel)
        await client.http.request(route, json={"content": "Hello world!"})
Ejemplo n.º 4
0
async def on_ready():
    await client.connected.wait()
    print("h!")
    if env.get("ENVIRONMENT", "production") == "production":
        r = Route("POST",
                  "/applications/{user_id}/commands",
                  user_id=env["USER_ID"])
    else:
        r = Route("POST",
                  "/applications/{user_id}/guilds/{guild_id}/commands",
                  user_id=env["USER_ID"],
                  guild_id=env["GUILD_ID"])
    with open("commands.json") as f:
        commands = load(f)

    for command in commands:
        await client.http.request(r, json=command)
Ejemplo n.º 5
0
 async def add_reaction(self, reaction):
     r = Route(
         "PUT",
         "/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me",
         channel_id=self.ctx.message.channel_id,
         message_id=self.message_id,
         emoji=reaction)
     await self.ctx.client.http.request(r)
Ejemplo n.º 6
0
    async def revoke_access(self, guild, user):
        guild = self._get_guild(guild)
        user = self._get_user(user)

        route = Route("POST",
                      "/{guild_id}/bot/{bot_id}/revoke_access",
                      guild_id=guild,
                      bot_id=self.bot_id)
        await self.http.request(route, json=user)
Ejemplo n.º 7
0
async def on_member_join(data, _):
    user_id = data["user"]["id"]
    guild_id = data["guild_id"]
    route = Route("PUT",
                  "/guilds/{guild_id}/members/{user_id}/roles/{role_id}",
                  guild_id=guild_id,
                  user_id=user_id,
                  role_id=choice(roles))
    await client.http.request(route)
Ejemplo n.º 8
0
    async def get_config(self, guild):
        guild = self._get_guild(guild)

        route = Route("GET",
                      "/{guild_id}/bot/{bot_id}/get_config",
                      guild_id=guild,
                      bot_id=self.bot_id)
        r = await self.http.request(route)
        return await r.json()
Ejemplo n.º 9
0
 async def update(self):
     r = Route("PATCH",
               "/channels/{channel_id}/messages/{message_id}",
               channel_id=self.ctx.message.channel_id,
               message_id=self.message_id)
     try:
         await self.ctx.client.http.request(
             r, json={"embeds": [self.get_page()]})
     except NotFound:
         await self.expire()
Ejemplo n.º 10
0
async def handle_request(data: dict):
    request_data = data["data"]
    method = request_data["method"]
    path = request_data["path"]
    params = request_data["route_params"]
    kwargs = params["kwargs"]

    route = Route(method, path, **params)
    logger.debug(f"{method} {path}")
    r = await client.http.request(route, **kwargs)
    if r.status < 200 or r.status >= 300:
        logger.warning(await r.text())
Ejemplo n.º 11
0
 async def remove_reaction(self, reaction):
     r = Route(
         "DELETE",
         "/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/{user_id}",
         channel_id=self.ctx.message.channel_id,
         message_id=self.message_id,
         emoji=reaction,
         user_id=self.author)
     try:
         await self.ctx.client.http.request(r)
     except Forbidden:
         pass
Ejemplo n.º 12
0
 async def expire(self):
     if self.expired:
         return
     self.expired = True
     r = Route("DELETE",
               "/channels/{channel_id}/messages/{message_id}",
               channel_id=self.ctx.message.channel_id,
               message_id=self.message_id)
     try:
         await self.ctx.client.http.request(r)
     except HTTPException:
         pass
     contexts.remove(self)
Ejemplo n.º 13
0
    async def publish(self, ctx: CommandContext, channel, description):
        if (int(ctx.message.member["permissions"]) & 0x20000000) != 0x20000000:
            return await ctx.send("You need manage webhooks to use this command!")

        r = Route("GET", "/channels/{news_channel_id}", news_channel_id=channel)
        res = await (await self.client.http.request(r)).json()
        if res["type"] != 5:
            return await ctx.send("You can only submit news channels!")

        if (await self.client.elastic.get(index="channels", id=channel, ignore=404))["found"]:
            return await ctx.send("Already submitted. Delete it with /delete")
        await self.client.elastic.index(index="channels", id=channel,
                                        body={"id": channel, "name": res["name"], "description": description})
        await self.client.elastic.indices.refresh(index="channels")
        await ctx.send("Listing created!")
Ejemplo n.º 14
0
async def on_message(message, shard):
    ctx = MessageContext(client, message)
    if not ctx.content.startswith(prefix):
        return
    clean_content = ctx.content[len(prefix):]
    args = clean_content.split(" ")
    command = args[0]
    del args[0]

    if perms_role not in ctx.member["roles"]:
        await ctx.send(content="No permissions!")
    if command == "createbot":
        bot_id = args[0]
        route = Route("GET", "/users/{user_id}", user_id=bot_id)
        r = await client.http.request(route)
        if r.status == 404:
            return await ctx.send(content="Bot not found!")
        user_data = await r.json()
        if not user_data.get("bot", False):
            return await ctx.send(content="User is not a bot")

        avatar = f"https://cdn.discordapp.com/avatars/{bot_id}/{user_data['avatar']}"
        secret_key = "".join(choices(ascii_letters + digits, k=40))

        try:
            bot_data_table.insert_one({
                "_id": int(bot_id),
                "icon": avatar,
                "name": user_data["username"]
            })
            bot_tokens_table.insert_one({
                "_id": int(bot_id),
                "token": secret_key
            })
        except:
            return await ctx.send(content="Bot is already added")

        await ctx.send(content=f"Ok! Created bot. Token: ||{secret_key}||")
    elif command == "removebot":
        bot_id = int(args[0])
        bot_data_table.delete_one({"_id": bot_id})
        bot_tokens_table.delete_one({"_id": bot_id})
        await ctx.send(content="Ok.")
Ejemplo n.º 15
0
    async def on_reaction(self, data):
        emoji = uriencode(data["emoji"]["name"])
        if emoji == "%E2%97%80%EF%B8%8F":
            self.active_page -= 1
            await self.update()
            await self.remove_reaction("%E2%97%80%EF%B8%8F")
        elif emoji == "%E2%9D%A4%EF%B8%8F":
            if (int(self.ctx.message.member["permissions"])
                    & 0x20000000) != 0x20000000:
                await self.ctx.send(
                    f"<@{self.author}> Uh oh, you need manage webhooks permissions to add news!"
                )
                return
            try:
                page = self.results[self.active_page]
            except IndexError:
                await self.ctx.send(
                    f"<@{self.author}> Uh oh, theres no channel selected here."
                    " Select a channel and press the heart to add it!")
                return
            await self.expire()

            r = Route("POST",
                      "/channels/{news_channel_id}/followers",
                      news_channel_id=page["id"])
            try:
                await self.ctx.client.http.request(
                    r,
                    json={"webhook_channel_id": self.ctx.message.channel_id})
            except Forbidden:
                await self.ctx.send(
                    "I need manage webhooks permissions to work!")
        elif emoji == "%E2%9E%A1%EF%B8%8F":
            self.active_page += 1
            await self.update()
            await self.remove_reaction("%E2%9E%A1%EF%B8%8F")
Ejemplo n.º 16
0
def send_message(channel_id):
    return Route("POST", "/channels/{channel_id}/messages", channel_id=channel_id)
Ejemplo n.º 17
0
 async def send(self, **kwargs):
     route = Route("POST", "/channels/{channel_id}/messages", channel_id=self.channel_id)
     return await self.client.http.request(route, json=kwargs)