-
Notifications
You must be signed in to change notification settings - Fork 13
/
mock_cmd.py
executable file
·55 lines (44 loc) · 1.36 KB
/
mock_cmd.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
#!/usr/bin/env python3
import sys
from pprint import pprint
import requests
import code_eval
import config
class MockCmd:
def __init__(self):
if len(sys.argv) == 2:
self.args = sys.argv[1]
else:
self.args = ''
self.sender = {'username': 'testname', 'pretty_name': 'testname', 'id': '1'}
self.channel_id = '1'
self.bot = MockBot()
def reply(self, text, embed=None, files=None):
print(text)
if embed:
pprint(embed)
if files:
pprint(files.keys())
class MockBot:
def __init__(self):
self.channels = {'1': '109469702010478592'}
self.guilds = {'109469702010478592': MockGuild()}
def send_message(self, channel_id, text, embed=None, files=None):
print(channel_id, text, embed, files)
def get(self, path):
response = requests.get('https://discord.com/api' + path, headers={
'Authorization': 'Bot ' + config.bot.token,
'User-Agent': 'DiscordBot (https://github.com/raylu/sbot 0.0)',
}, timeout=5.0)
response.raise_for_status()
return response.json()
def get_message(self, channel_id, message_id):
return self.get('/channels/%s/messages/%s' % (channel_id, message_id))
class MockGuild:
def __init__(self):
self.roles = {
'sbot': {'position': 3},
'dogs': {'position': 1, 'name': 'dogs', 'color': 123456, 'id': '1111'},
'cats': {'position': 2, 'name': 'cats', 'color': 13369480, 'id': '2222'},
}
code_eval.nodejs(MockCmd())