You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

34 lines
925 B

from discord.ext import tasks
import discord
import traceback
import asyncio
class Extension:
show_stats_prev = 0
core = None
def __init__(self, core):
self.core = core
async def task(self, timeout = 3):
await self.core.wait_until_ready()
while True:
await self.updater()
await asyncio.sleep(timeout)
async def updater(self):
try:
if not self.core.stats['servers'].values():
print("Stats not be loaded")
return
try:
server = list(self.core.stats['servers'].values())[self.show_stats_prev]
self.show_stats_prev += 1
except:
self.show_stats_prev = 0
server = list(self.core.stats['servers'].values())[self.show_stats_prev]
addr = server['address'].split(":")
act = discord.Streaming(name = f"{server['name']} - {server['player_count']}", url=f"https://{addr[0]}/connect/{addr[1]}")
await self.core.change_presence(activity=act)
except:
traceback.print_exc()