-
Notifications
You must be signed in to change notification settings - Fork 3
/
status_rotator.py
47 lines (39 loc) · 1.38 KB
/
status_rotator.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
import asyncio
import requests
from discord.ext import commands, tasks
class StatusRotator(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.url = "https://discord.com/api/v8/users/@me/settings"
self.change_status.start()
def cog_unload(self):
self.change_status.stop()
@tasks.loop(seconds=3)
async def change_status(self):
statuses = getattr(self, "statuses", [])
if statuses:
for status in statuses:
await self._change_status(status)
await asyncio.sleep(15) # Wait for 3 seconds
async def _change_status(self, message):
header = {
"authorization": ""
}
json_data = {
"status": "dnd",
"custom_status": {
"text": message
}
}
requests.patch(self.url, headers=header, json=json_data)
@commands.command()
async def setrotator(self, ctx, *, statuses):
# Split statuses by commas
self.statuses = [status.strip() for status in statuses.split(',')]
await ctx.send("`-` **ROTATING STATUS HAVE BEEN SET**")
@commands.command()
async def stoprotator(self, ctx):
self.change_status.stop()
await ctx.send("`-` **STATUS ROTATION STOPPED**")
def setup(bot):
bot.add_cog(StatusRotator(bot))