Move some count commands over to a separate cog

This commit is contained in:
Ave 2021-02-13 01:47:00 +03:00
parent cdd98f49b5
commit 4450573013
No known key found for this signature in database
GPG key ID: 398DD7BD03276F6D
3 changed files with 39 additions and 27 deletions

View file

@ -27,29 +27,11 @@ class Basic(Cog):
"""Converts base 10 to 16""" """Converts base 10 to 16"""
await ctx.send(f"{ctx.author.mention}: {int(num, 16)}") await ctx.send(f"{ctx.author.mention}: {int(num, 16)}")
@commands.guild_only()
@commands.command()
async def communitycount(self, ctx):
"""Prints the community member count of the server."""
community = ctx.guild.get_role(config.named_roles["community"])
await ctx.send(
f"{ctx.guild.name} has " f"{len(community.members)} community members!"
)
@commands.guild_only()
@commands.command()
async def hackercount(self, ctx):
"""Prints the hacker member count of the server."""
h4x0r = ctx.guild.get_role(config.named_roles["hacker"])
await ctx.send(
f"{ctx.guild.name} has " f"{len(h4x0r.members)} people with hacker role!"
)
@commands.guild_only() @commands.guild_only()
@commands.command() @commands.command()
async def membercount(self, ctx): async def membercount(self, ctx):
"""Prints the member count of the server.""" """Prints the member count of the server."""
await ctx.send(f"{ctx.guild.name} has " f"{ctx.guild.member_count} members!") await ctx.send(f"{ctx.guild.name} has {ctx.guild.member_count} members!")
@commands.command(aliases=["robocopng", "robocop-ng"]) @commands.command(aliases=["robocopng", "robocop-ng"])
async def robocop(self, ctx): async def robocop(self, ctx):
@ -75,7 +57,7 @@ class Basic(Cog):
gw_ms = self.bot.latency * 1000 gw_ms = self.bot.latency * 1000
message_text = ( message_text = (
f":ping_pong:\n" f"rtt: `{rtt_ms:.1f}ms`\n" f"gw: `{gw_ms:.1f}ms`" f":ping_pong:\nrtt: `{rtt_ms:.1f}ms`\ngw: `{gw_ms:.1f}ms`"
) )
self.bot.log.info(message_text) self.bot.log.info(message_text)
await tmp.edit(content=message_text) await tmp.edit(content=message_text)

30
cogs/basic_reswitched.py Normal file
View file

@ -0,0 +1,30 @@
import config
from discord.ext import commands
from discord.ext.commands import Cog
class BasicReswitched(Cog):
def __init__(self, bot):
self.bot = bot
@commands.guild_only()
@commands.command()
async def communitycount(self, ctx):
"""Prints the community member count of the server."""
community = ctx.guild.get_role(config.named_roles["community"])
await ctx.send(
f"{ctx.guild.name} has {len(community.members)} community members!"
)
@commands.guild_only()
@commands.command()
async def hackercount(self, ctx):
"""Prints the hacker member count of the server."""
h4x0r = ctx.guild.get_role(config.named_roles["hacker"])
await ctx.send(
f"{ctx.guild.name} has {len(h4x0r.members)} people with hacker role!"
)
def setup(bot):
bot.add_cog(BasicReswitched(bot))

View file

@ -35,7 +35,7 @@ class Robocronp(Cog):
job_details = repr(ctab[jobtype][jobtimestamp][job_name]) job_details = repr(ctab[jobtype][jobtimestamp][job_name])
embed.add_field( embed.add_field(
name=f"{jobtype} for {job_name}", name=f"{jobtype} for {job_name}",
value=f"Timestamp: {jobtimestamp}, " f"Details: {job_details}", value=f"Timestamp: {jobtimestamp}, Details: {job_details}",
inline=False, inline=False,
) )
await ctx.send(embed=embed) await ctx.send(embed=embed)
@ -82,7 +82,7 @@ class Robocronp(Cog):
target = await self.bot.fetch_user(int(job_name)) target = await self.bot.fetch_user(int(job_name))
if target: if target:
await target.send( await target.send(
"You asked to be reminded about" f" `{text}` on {added_on}." f"You asked to be reminded about `{text}` on {added_on}."
) )
delete_job(timestamp, jobtype, job_name) delete_job(timestamp, jobtype, job_name)
except: except:
@ -105,12 +105,12 @@ class Robocronp(Cog):
if len(purge_res) != 100: if len(purge_res) != 100:
done_cleaning = True done_cleaning = True
await log_channel.send( await log_channel.send(
f"Wiped {count} messages from " f"<#{channel.id}> automatically." f"Wiped {count} messages from <#{channel.id}> automatically."
) )
except: except:
# Don't kill cronjobs if something goes wrong. # Don't kill cronjobs if something goes wrong.
await log_channel.send( await log_channel.send(
"Cronclean has errored: ```" f"{traceback.format_exc()}```" f"Cronclean has errored: ```{traceback.format_exc()}```"
) )
async def minutely(self): async def minutely(self):
@ -131,7 +131,7 @@ class Robocronp(Cog):
except: except:
# Don't kill cronjobs if something goes wrong. # Don't kill cronjobs if something goes wrong.
await log_channel.send( await log_channel.send(
"Cron-minutely has errored: ```" f"{traceback.format_exc()}```" f"Cron-minutely has errored: ```{traceback.format_exc()}```"
) )
await asyncio.sleep(60) await asyncio.sleep(60)
@ -151,7 +151,7 @@ class Robocronp(Cog):
except: except:
# Don't kill cronjobs if something goes wrong. # Don't kill cronjobs if something goes wrong.
await log_channel.send( await log_channel.send(
"Cron-hourly has errored: ```" f"{traceback.format_exc()}```" f"Cron-hourly has errored: ```{traceback.format_exc()}```"
) )
# Your stuff that should run an hour after boot # Your stuff that should run an hour after boot
# and after that every hour goes here # and after that every hour goes here
@ -170,7 +170,7 @@ class Robocronp(Cog):
except: except:
# Don't kill cronjobs if something goes wrong. # Don't kill cronjobs if something goes wrong.
await log_channel.send( await log_channel.send(
"Cron-daily has errored: ```" f"{traceback.format_exc()}```" f"Cron-daily has errored: ```{traceback.format_exc()}```"
) )
await asyncio.sleep(86400) await asyncio.sleep(86400)
# Your stuff that should run a day after boot # Your stuff that should run a day after boot