-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient_poster.py
88 lines (66 loc) · 1.97 KB
/
client_poster.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
try:
import discord
except ModuleNotFoundError:
print('Discord.py is not installed!')
quit()
import dbots
# Go to https://requestbin.net and replace the path with the given URL
class TestService(dbots.Service):
@staticmethod
def _post(
http_client, bot_id, token, server_count=0, user_count=0,
voice_connections=0, shard_count=None, shard_id=None
):
payload = {
'server_count': server_count,
'user_count': user_count,
'voice_connections': voice_connections
}
if shard_id and shard_count:
payload['shard_id'] = shard_id
payload['shard_count'] = shard_count
return http_client.request(
method='POST',
path='http://requestbin.net/r/XXXXXX',
query={'id': bot_id},
headers={'Authorization': token},
json=payload
)
dbots.Service.SERVICE_KEYMAP['test'] = TestService
client = discord.Client()
poster = dbots.ClientPoster(client, 'discord.py', api_keys={
'test': 'token'
})
@poster.event
async def on_post(response):
print('Post:', response)
@poster.event
async def on_post_fail(error):
print('Post Fail:', error)
@poster.event
async def on_auto_post(response):
print('Auto-Post:', response)
@poster.event
async def on_auto_post_fail(error):
print('Auto-Post Fail:', error)
@client.event
async def on_ready():
print('Logged on as', client.user)
await poster.post()
poster.start_loop(10)
@client.event
async def on_message(message):
# don't respond to ourselves
if message.author == client.user:
return
if message.content.startswith('e> '):
code = message.content[3:]
output = ''
try:
output = str(eval(code))
except Exception as e:
output = str(e)
await message.channel.send(f'```py\n{output}\n```')
if message.content.startswith('p>'):
await poster.post()
client.run('XXX')