This repository has been archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_cog.py
46 lines (43 loc) · 2 KB
/
util_cog.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
import discord, db_handler as dbh
from asyncio import Lock
from discord.ext import commands
from discord import utils
from typing import Union
import functions
class Utility(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.guild_only()
@commands.command(
name='recount', aliases=['count', 'update', 'rc', 'r'],
description='Recount the emojis on a message as well as the linked messages on starboards',
brief='Recount points on message'
)
@commands.has_permissions(manage_messages=True)
@commands.cooldown(1, 2, commands.BucketType.guild)
async def force_recount(self, ctx, channel: discord.TextChannel, message_id: int):
if ctx.author.bot:
return
if ctx.guild.id not in dbh.database.locks:
dbh.database.locks[ctx.guild.id] = Lock()
if channel is not None:
channel = channel.id
else:
await ctx.send("I could not find a channel with that name or id")
return
failed = False
async with dbh.database.locks[ctx.guild.id]:
if channel in dbh.database.db['guilds'][ctx.guild.id]['channels']:
if message_id in dbh.database.db['guilds'][ctx.guild.id]['channels'][channel]['messages']:
original_channel_id, original_message_id = dbh.database.db['guilds'][ctx.guild.id]['channels'][channel]['messages'][message_id]
original_channel = utils.get(ctx.guild.channels, id=original_channel_id)
failed = await functions.recount_stars(ctx.guild, original_channel, original_message_id, self.bot)
else:
failed = True
else:
channel_object = utils.get(ctx.guild.channels, id=channel)
failed = await functions.recount_stars(ctx.guild, channel_object, message_id, self.bot)
if failed:
await ctx.send("Unable to recount stars on that message")
else:
await ctx.send("Done!")