-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
122 lines (95 loc) · 2.84 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
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
import logging
import time
import json
from discord.ext import commands
import storcord
import config
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('discord').setLevel(logging.INFO)
logging.getLogger('websockets').setLevel(logging.INFO)
log = logging.getLogger(__name__)
def gay_only():
return commands.check(lambda m: m.author.id in \
(162819866682851329, 97104885337575424, 150745989836308480))
class StorcordBot(commands.Bot):
def __init__(self, *args, **kwargs):
super().__init__(*args,**kwargs)
self.storcord = storcord.StorcordClient(self, \
config.storcord_guild, config.storcord_collections)
async def on_ready(self):
log.info(f'Logged in! {self.user!s}')
await self.storcord.ready()
async def on_message(self, message):
author = message.author
if author.bot: return
try:
guild = message.guild
except AttributeError:
# in a DM
return
ctx = await self.get_context(message)
await self.invoke(ctx)
bot = StorcordBot(description='im shit', command_prefix='stor!')
@bot.command()
async def ping(ctx):
"""pinge!"""
t1 = time.monotonic()
m = await ctx.send('.')
t2 = time.monotonic()
delta = round((t2 - t1) * 1000, 2)
await m.edit(content=f'{delta}ms')
@bot.command()
@gay_only()
async def insert(ctx, *, data: str):
"""Insert a document."""
try:
j = json.loads(data)
except:
return await ctx.send('Failed to parse JSON')
res = await ctx.bot.storcord.insert_one(j)
await ctx.send(res)
@bot.command()
async def idxdb(ctx):
"""Show IndexDB."""
await ctx.send(repr(ctx.bot.storcord.indexdb))
@bot.command()
@gay_only()
async def saveidxdb(ctx):
"""Save IndexDB."""
await ctx.bot.storcord.save_indexdb()
await ctx.send('ok')
@bot.command()
async def squery(ctx, *, raw: str):
"""Make a simple query"""
try:
raw = json.loads(raw)
except:
raw = {'raw': raw}
res = await ctx.bot.storcord.simple_query(raw)
await ctx.send(repr(res))
@bot.command()
@gay_only()
async def sdel(ctx, *, raw: str):
"""Delete a document through simple query.
Equals to deleteOne from Mongo.
"""
try:
raw = json.loads(raw)
except:
raw = {'raw': raw}
res = await ctx.bot.storcord.delete_one(raw)
await ctx.send(repr(res))
@bot.command()
@gay_only()
async def supd(ctx, query: str, *, data: str):
"""Update a document."""
try:
await ctx.send(f'`{repr(query)}`')
await ctx.send(f'`{repr(data)}`')
query = json.loads(query)
data = json.loads(data)
except:
return await ctx.send('Failed to parse json u dumb slut bitch')
await ctx.send(await ctx.bot.storcord.update_one(query, data))
bot.load_extension('exec')
bot.run(config.token)