This repository has been archived by the owner on Aug 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
bot.py
80 lines (56 loc) · 2.38 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import io
import logging
import os
import aiohttp
import discord
import neispy
from discord.ext import commands
import cogs
import database
import utils
logging.basicConfig(level=logging.INFO)
class Bot(commands.Bot):
__version__ = "1.3.1"
def __init__(self, *args, **kwargs):
self.initialize_autoembed()
super().__init__(*args, **kwargs)
self.neis = neispy.Client(os.environ["API_KEY"])
cogs.load(self)
self.load_extension("jishaku")
self.loop.create_task(database.init())
def initialize_autoembed(self):
send_method = discord.abc.Messageable.send
async def send(self, content=None, **kwargs):
if "embed" in kwargs and kwargs.get("mobile", True):
if not content:
content = ""
content += "\n" * 2 + utils.embed_to_text(kwargs["embed"])
if kwargs["embed"].image.url != discord.Embed.Empty:
content += "\n" * 2 + kwargs["embed"].image.url
del kwargs["embed"]
if "mobile" in kwargs:
del kwargs["mobile"]
return await send_method(self, content, **kwargs)
discord.abc.Messageable.send = send
edit_method = discord.Message.edit
async def edit(self, **kwargs):
if "embed" in kwargs and kwargs.get("mobile", True):
if not "content" in kwargs:
kwargs["content"] = ""
kwargs["content"] += "\n" * 2 + utils.embed_to_text(kwargs["embed"])
if kwargs["embed"].image.url != discord.Embed.Empty:
async with aiohttp.ClientSession() as session:
async with session.get(kwargs["embed"].image.url) as resp:
await self.channel.send(
file=discord.File(
io.BytesIO(await resp.content.read()),
filename=f"image{os.path.splitext(kwargs['embed'].image.url)[1]}",
)
)
del kwargs["embed"]
if "mobile" in kwargs:
del kwargs["mobile"]
return await edit_method(self, **kwargs)
discord.Message.edit = edit
if __name__ == "__main__":
Bot(command_prefix="?", help_command=None).run(os.environ["TOKEN"])