-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
164 lines (139 loc) · 4.44 KB
/
main.py
File metadata and controls
164 lines (139 loc) · 4.44 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import os
os.system("pip install resql==0.1.5")
from prettyprinter import pprint
import os,discord,requests,util,asyncio,io,contextlib,textwrap
import time,random,math,aiohttp,numpy,config
import colorful as cf
import popcat_wrapper.popcat_wrapper as pop
from aioify import aioify
from urllib.parse import quote
from discord.ext import commands
from discord.ext.commands import when_mentioned_or
from keep_alve import keep_alive
from traceback import format_exception
from datetime import datetime
from resql import ReSql
from color import Color
from threading import Thread
prefixes: tuple = ("py!", "PY!", "Py!", "pY!")
cf.use_style("monokai")
bot = commands.Bot(
allowed_mentions=discord.AllowedMentions.none(),
command_prefix=when_mentioned_or("py!", "PY!", "Py!", "pY!"),
case_insensitive=True,
intents=discord.Intents.all(),
strip_after_prefix=True,
owner_ids=config.owners,
help_command=None
)
db = ReSql("gibmeyanfei.db")
class Utilities:
def botCommands(separator=", "):
return separator.join([str(each) for each in list(bot.commands)])
def serverNames(separator=", "):
return separator.join([str(each) for each in list(bot.guilds)])
async def channelSendMessage(channelID,message:str):
await bot.get_channel(channelID).send(message)
bot.db = db
bot.func = util
bot.test_func = Utilities
bot.key = os.getenv("key")
bot.Color = Color ; bot.Colour = Color
bot.time = time.time()
keep_alive()
def berker(text):
time = None
text = quote(str(text))
who = bot.get_user(551786741296791562)
name = quote(str(who.name))
avatar = who.avatar_url
url = f"https://api-production-adc9.up.railway.app/discordsays?avatar={avatar}&username={name}&message={text}"
r = requests.get(url)
with open("./dumb_shit/berk.png","wb") as thefile:
thefile.write(r.content)
berk_maker_9000 = aioify(obj=berker)
@bot.event
async def on_ready():
print(cf.green(f"Logged in as {bot.user}!\n|-----------------------------------------|"))
@bot.event
async def on_connect():
print(cf.green("Connected to discord!"))
@bot.event
async def on_message_edit(before, after):
if after.content != before.content:
await bot.process_commands(after)
@bot.listen("on_message")
async def ping_for_prefix(message):
if (message.author.bot):
return
if (message.author == bot.user):
return
if (f"<@!{bot.user.id}>" in message.content) or (f"<@{bot.user.id}>" in message.content):
embed = discord.Embed(
description=f"Hi **{message.author.name}**! My prefix is `Py!`, run `Py!help` to get started.",
color=message.author.color
)
embed.set_author(name="PyBot", icon_url=bot.user.avatar_url)
embed.set_footer(text="The prefix and all commands are case insensitive")
await message.reply(embed=embed)
@bot.command()
async def berk(ctx,*,text):
await berk_maker_9000(text)
file = discord.File("./dumb_shit/berk.png")
await ctx.reply(file=file)
os.remove("dumb_shit/berk.png")
@bot.command(name="alteval")
@commands.is_owner()
async def _eval(ctx, *, code):
from util import clean_code
from pag import Pag
await ctx.reply("Let me evaluate this code for you! Won't be a sec")
code = clean_code(code)
local_variables = {
"discord": discord,
"commands": commands,
"bot": bot,
"ctx": ctx,
"commands": commands,
"os": os,
"import": __import__,
"random": random,
"pop": pop,
"utils": util,
"time": time,
"math": math,
"numpy": numpy,
"aiohttp": aiohttp,
"requests": requests,
"asyncio": asyncio,
"channel": ctx.channel,
"author": ctx.author,
"guild": ctx.guild,
"message": ctx.message
}
stdout = io.StringIO()
try:
with contextlib.redirect_stdout(stdout):
exec(
f"async def func():\n{textwrap.indent(code, ' ')}", local_variables,
)
obj = await local_variables["func"]()
result = f"{stdout.getvalue()}\n-- {obj}\n"
except Exception as e:
result = "".join(format_exception(e, e, e.__traceback__))
pager = Pag(
colour=ctx.author.color,
timeout=100,
title="Paginator paginating pagination",
entries=[result[i : i + 1000] for i in range(0, len(result), 1000)],
length=1,
prefix="```py\n",
suffix="```",
)
await pager.start(ctx)
if __name__ == "__main__":
for cog in os.listdir('./Cogs'):
if (cog.endswith(".py")) and not (cog.startswith("_")):
bot.load_extension(f'Cogs.{cog[:-3]}')
bot.load_extension("jishaku")
bot.run(os.getenv("token"))