(topgg): Minor linting and wording changes.

This commit is contained in:
2022-01-19 15:08:27 +02:00
parent 2ff4805d6c
commit 153ebcbe37
5 changed files with 60 additions and 38 deletions

View File

@@ -1,29 +1,30 @@
import discord import discord
from .module import module from .module import module
from wards import guild_admin from wards import guild_admin
from bot.cmdClient.checks.global_perms import in_guild from bot.cmdClient.checks import in_guild, is_owner
from settings.user_settings import UserSettings from settings.user_settings import UserSettings
from .webhook import on_dbl_vote from .webhook import on_dbl_vote
from .utils import * from .utils import lion_loveemote
@module.cmd( @module.cmd(
"forcevote", "forcevote",
desc="Simulate Topgg Vote.", desc="Simulate a Topgg Vote from the given user.",
group="Guild Admin", group="Bot Admin",
aliases=('debugvote', 'topggvote')
) )
@guild_admin() @is_owner()
async def cmd_forcevote(ctx): async def cmd_forcevote(ctx):
""" """
Usage``: Usage``:
{prefix}forcevote {prefix}forcevote
Description: Description:
Simulate Topgg Vote without actually a confirmation from Topgg site. Simulate Top.gg vote without actually a confirmation from Topgg site.
Can be used for force a vote for testing or if topgg has an error or production time bot error. Can be used for force a vote for testing or if topgg has an error or production time bot error.
""" """
target = ctx.author target = ctx.author
# Identify the target # Identify the target
if ctx.args: if ctx.args:
if not ctx.msg.mentions: if not ctx.msg.mentions:
@@ -36,7 +37,7 @@ async def cmd_forcevote(ctx):
@module.cmd( @module.cmd(
"vote", "vote",
desc="Get top.gg boost for 25% more LCs.", desc="[Vote](https://top.gg/bot/889078613817831495/vote) for me to get 25% more LCs!",
group="Economy", group="Economy",
aliases=('topgg', 'topggvote', 'upvote') aliases=('topgg', 'topggvote', 'upvote')
) )
@@ -48,11 +49,12 @@ async def cmd_vote(ctx):
Description: Description:
Get Top.gg bot's link for +25% Economy boost. Get Top.gg bot's link for +25% Economy boost.
""" """
target = ctx.author embed = discord.Embed(
embed=discord.Embed(
title="Claim your boost!", title="Claim your boost!",
description='Please click [here](https://top.gg/bot/889078613817831495/vote) vote and support our bot!\n\nThank you! {}.'.format(lion_loveemote), description=(
"Please click [here](https://top.gg/bot/889078613817831495/vote) to vote and support our bot!\n\n"
"Thank you! {}.".format(lion_loveemote)
),
colour=discord.Colour.orange() colour=discord.Colour.orange()
).set_thumbnail( ).set_thumbnail(
url="https://cdn.discordapp.com/attachments/908283085999706153/933012309532614666/lion-love.png" url="https://cdn.discordapp.com/attachments/908283085999706153/933012309532614666/lion-love.png"

View File

@@ -1,31 +1,30 @@
from multiprocessing import context
from LionModule import LionModule from LionModule import LionModule
from LionContext import register_reply_callback, unregister_reply_callback from LionContext import register_reply_callback, unregister_reply_callback
from bot.data.conditions import NOT
from meta.client import client
from core.lion import Lion from core.lion import Lion
from .utils import * from .utils import get_last_voted_timestamp, lion_loveemote, lion_yayemote
from .webhook import init_webhook from .webhook import init_webhook
module = LionModule("Topgg") module = LionModule("Topgg")
upvote_info = "You have a boost available {}, to support our project and earn **25% more LionCoins** type `{}vote` {}" upvote_info = "You have a boost available {}, to support our project and earn **25% more LionCoins** type `{}vote` {}"
@module.launch_task @module.launch_task
async def register_hook(client): async def register_hook(client):
init_webhook() init_webhook()
register_reply_callback(reply) register_reply_callback(reply)
Lion.register_economy_bonus(economy_bonus) Lion.register_economy_bonus(economy_bonus)
client.log("Registered LionContext reply util hook.", context="Topgg" ) client.log("Registered LionContext reply util hook.", context="Topgg")
@module.unload_task @module.unload_task
async def unregister_hook(client): async def unregister_hook(client):
unregister_reply_callback(reply) unregister_reply_callback(reply)
Lion.unregister_economy_bonus(economy_bonus) Lion.unregister_economy_bonus(economy_bonus)
client.log("Unregistered LionContext reply util hook.", context="Topgg" ) client.log("Unregistered LionContext reply util hook.", context="Topgg")
def reply(util_func, *args, **kwargs): def reply(util_func, *args, **kwargs):

View File

@@ -4,7 +4,8 @@ from settings.setting_types import Boolean
from modules.reminders.reminder import Reminder from modules.reminders.reminder import Reminder
from modules.reminders.data import reminders from modules.reminders.data import reminders
from .utils import * from .utils import create_remainder, remainder_content
@UserSettings.attach_setting @UserSettings.attach_setting
class topgg_vote_remainder(Boolean, UserSetting): class topgg_vote_remainder(Boolean, UserSetting):

View File

@@ -12,14 +12,20 @@ from . import data as db
from data.conditions import GEQ from data.conditions import GEQ
topgg_upvote_link = 'https://top.gg/bot/889078613817831495/vote' topgg_upvote_link = 'https://top.gg/bot/889078613817831495/vote'
remainder_content = "You can now vote again on top.gg!\nClick [here]({}) to vote, thank you for the support!".format(topgg_upvote_link) remainder_content = (
"You can now vote again on top.gg!\n"
"Click [here]({}) to vote, thank you for the support!"
).format(topgg_upvote_link)
lion_loveemote = '<:lionloveemote:933003977656795136>' lion_loveemote = '<:lionloveemote:933003977656795136>'
lion_yayemote = '<:lionyayemote:933003929229352990>' lion_yayemote = '<:lionyayemote:933003929229352990>'
# Will return None if user has not voted in [-12.5hrs till now]
# else will return a Tuple containing timestamp of when exactly she voted
def get_last_voted_timestamp(userid: Integer): def get_last_voted_timestamp(userid: Integer):
"""
Will return None if user has not voted in [-12.5hrs till now]
else will return a Tuple containing timestamp of when exactly she voted
"""
return db.topggvotes.select_one_where( return db.topggvotes.select_one_where(
userid=userid, userid=userid,
select_columns="boostedTimestamp", select_columns="boostedTimestamp",
@@ -27,9 +33,12 @@ def get_last_voted_timestamp(userid: Integer):
_extra="ORDER BY boostedTimestamp DESC LIMIT 1" _extra="ORDER BY boostedTimestamp DESC LIMIT 1"
) )
# Checks if a remainder is already running (immaterial of remind_at time)
# If no remainder exists creates a new remainder and schedules it
def create_remainder(userid): def create_remainder(userid):
"""
Checks if a remainder is already running (immaterial of remind_at time)
If no remainder exists creates a new remainder and schedules it
"""
if not reminders.select_one_where( if not reminders.select_one_where(
userid=userid, userid=userid,
content=remainder_content, content=remainder_content,
@@ -46,7 +55,11 @@ def create_remainder(userid):
interval=None, interval=None,
title="Your boost is now available! {}".format(lion_yayemote), title="Your boost is now available! {}".format(lion_yayemote),
footer="Use `{}vote_reminder off` to stop receiving reminders.".format(client.prefix), footer="Use `{}vote_reminder off` to stop receiving reminders.".format(client.prefix),
remind_at=last_vote_time[0] + datetime.timedelta(hours=12.5) if last_vote_time else datetime.datetime.utcnow() + datetime.timedelta(minutes=5) remind_at=(
last_vote_time[0] + datetime.timedelta(hours=12.5)
if last_vote_time else
datetime.datetime.utcnow() + datetime.timedelta(minutes=5)
)
# remind_at=datetime.datetime.utcnow() + datetime.timedelta(minutes=2) # remind_at=datetime.datetime.utcnow() + datetime.timedelta(minutes=2)
) )
@@ -64,10 +77,13 @@ async def send_user_dm(userid):
pass pass
if user: if user:
try: try:
embed=discord.Embed( embed = discord.Embed(
title="Thank you for supporting our bot on Top.gg! {}".format(lion_yayemote), title="Thank you for supporting our bot on Top.gg! {}".format(lion_yayemote),
description="By voting every 12 hours you will allow us to reach and help even more students all over the world.\n \ description=(
Thank you for supporting us, enjoy your LionCoins boost!", "By voting every 12 hours you will allow us to reach and help "
"even more students all over the world.\n"
"Thank you for supporting us, enjoy your LionCoins boost!"
),
colour=discord.Colour.orange() colour=discord.Colour.orange()
).set_image( ).set_image(
url="https://cdn.discordapp.com/attachments/908283085999706153/932737228440993822/lion-yay.png" url="https://cdn.discordapp.com/attachments/908283085999706153/932737228440993822/lion-yay.png"

View File

@@ -4,7 +4,8 @@ from utils.lib import utc_now
from meta.config import conf from meta.config import conf
import topgg import topgg
from .utils import * from .utils import db, send_user_dm, create_remainder
@client.event @client.event
async def on_dbl_vote(data): async def on_dbl_vote(data):
@@ -13,7 +14,7 @@ async def on_dbl_vote(data):
db.topggvotes.insert( db.topggvotes.insert(
userid=data['user'], userid=data['user'],
boostedTimestamp = utc_now() boostedTimestamp=utc_now()
) )
await send_user_dm(data['user']) await send_user_dm(data['user'])
@@ -32,5 +33,8 @@ async def on_dbl_test(data):
def init_webhook(): def init_webhook():
client.topgg_webhook = topgg.WebhookManager(client).dbl_webhook(conf.bot.get("topgg_route"), conf.bot.get("topgg_password")) client.topgg_webhook = topgg.WebhookManager(client).dbl_webhook(
conf.bot.get("topgg_route"),
conf.bot.get("topgg_password")
)
client.topgg_webhook.run(conf.bot.get("topgg_port")) client.topgg_webhook.run(conf.bot.get("topgg_port"))