-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
159 lines (125 loc) · 3.78 KB
/
main.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
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
import io
import os
import logging
import random
import string
import textwrap
import contextlib
from traceback import format_exception
import discord
from discord.ext import commands
from conversations import Manager, Mongo, Helper, Plots
from conversations.datastore import Sqlite, ApiStore
from utils import StatBot
from utils.util import Pag
MONGO_URL = os.getenv("MONGO")
TOKEN = os.getenv("TOKEN")
logging.basicConfig(
format="%(levelname)s | %(asctime)s | %(module)s | %(message)s",
datefmt="%d/%m/%Y %I:%M:%S %p",
level=logging.INFO,
)
logger = logging.getLogger(__name__)
intents = discord.Intents.all()
bot = StatBot(
case_insensitive=True,
intents=intents,
activity=discord.Game(name="Playing with statistics"),
mongo=MONGO_URL,
)
bot.datastore = ApiStore()
# bot.datastore = Mongo(MONGO_URL)
# bot.datastore = Sqlite()
bot.manager = Manager(bot.datastore)
bot.internal_helpers = (
203104843479515136,
289546108751839232,
456174857034661888,
726531923131891782,
221091847412383754,
158063324699951104,
271612318947868673,
651386805043593237,
)
bot.internal_helpers = set(bot.internal_helpers)
bot.leadership = (271612318947868673, 158063324699951104)
bot.leadership = set(bot.leadership)
def get_random_string():
letters = string.ascii_lowercase
return "".join(random.choice(letters) for i in range(8))
@bot.command(enabled=True)
@commands.is_owner()
async def setup_helpers(ctx):
stuff = {}
for user_id in bot.internal_helpers:
member = ctx.guild.get_member(user_id)
password = get_random_string()
if user_id == 289546108751839232:
name = "InteriorHood"
else:
name = member.name
name = name.lower()
stuff[name] = password
await bot.datastore.store_helper(Helper(member.id), name, password, True)
print(stuff)
await ctx.send(stuff)
@bot.command()
@commands.is_owner()
async def logout(ctx):
"""Log's the bot out of discord"""
await ctx.send("Cya :wave:")
await bot.logout()
@bot.command(aliases=["gh"], enabled=False)
@commands.is_owner()
async def get_helpers(ctx):
"""Mongo Helpers -> SQlite"""
mongo = Mongo("MONGO_URL")
x = await mongo.fetch_helpers()
helpers = [x.identifier for x in x]
for h in helpers:
await bot.datastore.store_helper(Helper(identifier=h))
await ctx.send(helpers)
@bot.command(name="eval", aliases=["exec"], hidden=True)
@commands.is_owner()
async def _eval(ctx, *, code):
"""
Evaluates given code.
"""
code = bot.clean_code(code)
local_variables = {
"discord": discord,
"commands": commands,
"bot": bot,
"ctx": ctx,
"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(
entries=[result[i : i + 2000] for i in range(0, len(result), 2000)],
length=1,
prefix="```py\n",
suffix="```",
)
await pager.start(ctx)
if __name__ == "__main__":
for ext in os.listdir("./cogs/"):
if ext.endswith(".py") and not ext.startswith("_"):
try:
bot.load_extension(f"cogs.{ext[:-3]}")
except Exception as e:
print(
"An error occurred while loading ext cogs.{}: {}".format(
ext[:-3], e
)
)
bot.run(TOKEN)