-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_status.py
130 lines (112 loc) · 5.39 KB
/
custom_status.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
from discord.ext import commands
import discord
import asyncio
import random
import aiohttp
import os
import time
import json
from util_discord import check_if_not_owner
headers = {"authorization": os.getenv("LANYARD")}
async def the_real_req(url: str):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
return await response.json()
async def the_real_put(url: str, data: str):
async with aiohttp.ClientSession() as session:
async with session.put(url, headers=headers, data=data) as response:
return response
async def the_real_delete(url: str):
async with aiohttp.ClientSession() as session:
async with session.delete(url, headers=headers) as response:
return response
def read_json_file(file_path):
with open(file_path, 'r', encoding='utf-8') as json_file:
data = json.load(json_file)
return data
async def silly_activities(bot: commands.Bot):
while True:
if bot.is_ready():
try:
strings = [
f"serving {len(bot.users)} users in {len(bot.guilds)} guilds",
f"will return in {round(bot.latency * 1000) if bot.latency != float('inf') else '♾️'}ms",
time.strftime("%A, %d %B %Y"),
"🔴 = stable 🟢 = unstable",
"RADIO ONSEN EUTOPIA",
"bot by gdjkhp",
"made in yokohama, japan",
"hosted in germany",
"written in python",
"powered by pterodactyl",
"don't make me popular >_<",
]
data = await the_real_req(f"https://api.lanyard.rest/v1/users/{os.getenv('OWNER')}")
if data["success"]:
strings.append(f"gdjkhp is currently {data['data']['discord_status']}")
if data["data"]["kv"]:
for key in list(data["data"]["kv"]):
strings.append(data["data"]["kv"][key])
splashes = read_json_file("./res/mandatory_settings_and_splashes.json")["some funny splashes you can modify"]
strings.append(random.choice(splashes))
await bot.change_presence(activity=discord.CustomActivity(name=random.choice(strings)), status=discord.Status.dnd)
except Exception as e: print(f"Exception in silly_activities: {e}")
await asyncio.sleep(10)
def kv_embed(kv: dict):
e = discord.Embed(title="📝 Lanyard", description=f"{len(kv)} found", color=0x00ff00)
for key, value in kv.items(): e.add_field(name=key, value=value, inline=False)
return e
async def view_kv(ctx: commands.Context):
data = await the_real_req(f"https://api.lanyard.rest/v1/users/{os.getenv('OWNER')}")
await ctx.reply(embed=kv_embed(data["data"]["kv"]))
async def get_kv(ctx: commands.Context, key: str):
if not key: return await ctx.reply("no key provided")
data = await the_real_req(f"https://api.lanyard.rest/v1/users/{os.getenv('OWNER')}")
if not data["data"]["kv"] or not data["data"]["kv"].get(key): return await ctx.reply("no results found")
await ctx.reply(data["data"]["kv"][key])
async def set_kv(ctx: commands.Context, arg: str):
key = arg.split()[0]
value = " ".join(arg.split()[1:])
if not key or not value: return await ctx.reply("no key/value provided")
await the_real_put(f"https://api.lanyard.rest/v1/users/{os.getenv('OWNER')}/kv/{key}", value)
data = await the_real_req(f"https://api.lanyard.rest/v1/users/{os.getenv('OWNER')}")
await ctx.reply(embed=kv_embed(data["data"]["kv"]))
async def del_kv(ctx: commands.Context, key: str):
if not key: return await ctx.reply("no key provided")
await the_real_delete(f"https://api.lanyard.rest/v1/users/{os.getenv('OWNER')}/kv/{key}")
data = await the_real_req(f"https://api.lanyard.rest/v1/users/{os.getenv('OWNER')}")
await ctx.reply(embed=kv_embed(data["data"]["kv"]))
class LanyardUtil(commands.Cog):
def __init__(self, bot):
self.bot: commands.Bot = bot
@commands.command()
async def kvview(self, ctx: commands.Context):
if check_if_not_owner(ctx): return
await view_kv(ctx)
@commands.command()
async def kvget(self, ctx: commands.Context, key=None):
if check_if_not_owner(ctx): return
await get_kv(ctx, key)
@commands.command()
async def kvset(self, ctx: commands.Context, *, arg=None):
if check_if_not_owner(ctx): return
await set_kv(ctx, arg)
@commands.command()
async def kvdel(self, ctx: commands.Context, key=None):
if check_if_not_owner(ctx): return
await del_kv(ctx, key)
@commands.command()
async def sync(self, ctx: commands.Context):
if check_if_not_owner(ctx): return
synced = await self.bot.tree.sync()
await ctx.reply(f"Synced {len(synced)} slash commands")
@commands.command()
async def stats(self, ctx: commands.Context):
stat_list = [
f"serving {len(self.bot.users)} users in {len(self.bot.guilds)} guilds",
f"will return in {round(self.bot.latency * 1000) if self.bot.latency != float('inf') else '♾️'}ms",
f"{len(self.bot.tree.get_commands())} application commands found"
]
await ctx.reply("\n".join(stat_list))
async def setup(bot: commands.Bot):
await bot.add_cog(LanyardUtil(bot))