(guild_admin): statreset command.
Added the `statreset` command for resetting study statistics. Add the `Guild Admin` command group.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
from .module import module
|
from .module import module
|
||||||
|
|
||||||
from . import guild_config
|
from . import guild_config
|
||||||
|
from . import statreset
|
||||||
|
|||||||
65
bot/modules/guild_admin/statreset.py
Normal file
65
bot/modules/guild_admin/statreset.py
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
import discord
|
||||||
|
from wards import guild_admin
|
||||||
|
from data import tables
|
||||||
|
from core import Lion
|
||||||
|
|
||||||
|
from .module import module
|
||||||
|
|
||||||
|
|
||||||
|
@module.cmd("statreset",
|
||||||
|
desc="Perform a complete reset of the server's study statistics.",
|
||||||
|
group="Guild Admin")
|
||||||
|
@guild_admin()
|
||||||
|
async def cmd_statreset(ctx):
|
||||||
|
"""
|
||||||
|
Usage``:
|
||||||
|
{prefix}statreset
|
||||||
|
Description:
|
||||||
|
Perform a complete reset of the server's member statistics.
|
||||||
|
This includes tracked time, coins, and workout counts.
|
||||||
|
|
||||||
|
This may be used to set "seasons" of study.
|
||||||
|
|
||||||
|
Before the reset, I will send a csv file with the previous member statistics.
|
||||||
|
|
||||||
|
**This is not reversible.**
|
||||||
|
"""
|
||||||
|
if not await ctx.ask("Are you sure you want to completely reset the member statistics? "
|
||||||
|
"**THIS IS NOT REVERSIBLE!**"):
|
||||||
|
return
|
||||||
|
# Build the data csv
|
||||||
|
rows = tables.lions.select_where(
|
||||||
|
select_columns=('userid', 'tracked_time', 'coins', 'workout_count', 'b.roleid AS badge_roleid'),
|
||||||
|
_extra=(
|
||||||
|
"LEFT JOIN study_badges b ON last_study_badgeid = b.badgeid "
|
||||||
|
"WHERE members.guildid={}"
|
||||||
|
).format(ctx.guild.id)
|
||||||
|
)
|
||||||
|
header = "userid, tracked_time, coins, workouts, rank_roleid\n"
|
||||||
|
csv_rows = [
|
||||||
|
', '.join(str(data) for data in row)
|
||||||
|
for row in rows
|
||||||
|
]
|
||||||
|
|
||||||
|
with StringIO() as stats_file:
|
||||||
|
stats_file.write(header)
|
||||||
|
stats_file.write('\n'.join(csv_rows))
|
||||||
|
stats_file.seek(0)
|
||||||
|
|
||||||
|
out_file = discord.File(stats_file, filename="member_statistics.csv")
|
||||||
|
await ctx.reply(file=out_file)
|
||||||
|
|
||||||
|
# Reset the statistics
|
||||||
|
tables.lions.update_where(
|
||||||
|
{'tracked_time': 0, 'coins': 0, 'workout_count': 0},
|
||||||
|
guildid=ctx.guild.id
|
||||||
|
)
|
||||||
|
|
||||||
|
Lion.sync()
|
||||||
|
|
||||||
|
await ctx.embed_reply(
|
||||||
|
"The server member statistics have been reset!\n"
|
||||||
|
"(It may take a while for the member studybadges to update.)"
|
||||||
|
)
|
||||||
@@ -14,6 +14,7 @@ group_hints = {
|
|||||||
'Statistics': "*StudyLion leaderboards and study statistics.*",
|
'Statistics': "*StudyLion leaderboards and study statistics.*",
|
||||||
'Economy': "*Buy, sell, and trade with your hard-earned coins!*",
|
'Economy': "*Buy, sell, and trade with your hard-earned coins!*",
|
||||||
'Personal Settings': "*Tell me about yourself!*",
|
'Personal Settings': "*Tell me about yourself!*",
|
||||||
|
'Guild Admin': "*Dangerous administration commands!*",
|
||||||
'Guild Configuration': "*Control how I behave in your server.*",
|
'Guild Configuration': "*Control how I behave in your server.*",
|
||||||
'Meta': "*Information about me!*"
|
'Meta': "*Information about me!*"
|
||||||
}
|
}
|
||||||
@@ -28,7 +29,7 @@ mod_group_order = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
admin_group_order = (
|
admin_group_order = (
|
||||||
('Guild Configuration', 'Moderation', 'Meta'),
|
('Guild Admin', 'Guild Configuration', 'Moderation', 'Meta'),
|
||||||
('Productivity', 'Statistics', 'Economy', 'Personal Settings')
|
('Productivity', 'Statistics', 'Economy', 'Personal Settings')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user