diff --git a/cogs/statchannel.py b/cogs/statchannel.py new file mode 100644 index 0000000..ba64a06 --- /dev/null +++ b/cogs/statchannel.py @@ -0,0 +1,32 @@ +import aiohttp +from discord.ext import commands, tasks +import os + +class StatChannel(commands.Cog): + def __init__(self, bot): + self.bot = bot + self.channel_id = int(os.getenv('STRINOVA_STAT_CHANNEL_ID')) + self.update_stat.start() + + def cog_unload(self): + self.update_stat.cancel() + + @tasks.loop(minutes=10) + async def update_stat(self): + try: + async with aiohttp.ClientSession() as session: + async with session.get('https://api.steampowered.com/ISteamUserStats/GetNumberOfCurrentPlayers/v1/?appid=1282270') as r: + data = await r.json() + count = data['response']['player_count'] + channel = self.bot.get_channel(self.channel_id) + if channel: + await channel.edit(name=f'🎮 Players: {count:,}') + except Exception as e: + print(f'stat channel update failed: {e}') + + @update_stat.before_loop + async def before_update(self): + await self.bot.wait_until_ready() + +async def setup(bot): + await bot.add_cog(StatChannel(bot)) \ No newline at end of file diff --git a/main.py b/main.py index 3569036..f8e6edc 100644 --- a/main.py +++ b/main.py @@ -41,6 +41,7 @@ async def main(): await bot.load_extension('cogs.copypasta') await bot.load_extension('cogs.sysinfo') await bot.load_extension('music.music') + await bot.load_extension('cogs.statchannel') try: await bot.start(os.getenv('DISCORD_TOKEN')) diff --git a/twitterbridge/rss.py b/twitterbridge/rss.py index bb76192..71ae69e 100644 --- a/twitterbridge/rss.py +++ b/twitterbridge/rss.py @@ -102,4 +102,4 @@ class TwitterRSSForwarder: if resp.status not in (200, 204): print(f'twitter webhook post failed: {resp.status} {await resp.text()}') else: - print(f'twitter rss posted: {title[:60]}...') + print(f'twitter rss posted: {title[:60]}...') \ No newline at end of file