chore(rewrite): Remove deprecated code.

This commit is contained in:
2023-10-24 14:33:06 +03:00
parent 9f0b956a30
commit fef1ae1691
7 changed files with 0 additions and 381 deletions

View File

@@ -1,6 +0,0 @@
from .module import module
from . import webhook
from . import commands
from . import data
from . import settings

View File

@@ -1,77 +0,0 @@
import discord
from .module import module
from cmdClient.checks import is_owner
from settings.user_settings import UserSettings
from LionContext import LionContext
from .webhook import on_dbl_vote
from .utils import lion_loveemote
@module.cmd(
"forcevote",
desc="Simulate a Topgg Vote from the given user.",
group="Bot Admin",
)
@is_owner()
async def cmd_forcevote(ctx: LionContext):
"""
Usage``:
{prefix}forcevote
Description:
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.
"""
target = ctx.author
# Identify the target
if ctx.args:
if not ctx.msg.mentions:
return await ctx.error_reply("Please mention a user to simulate a vote!")
target = ctx.msg.mentions[0]
await on_dbl_vote({"user": target.id, "type": "test"})
return await ctx.reply('Topgg vote simulation successful on {}'.format(target), suggest_vote=False)
@module.cmd(
"vote",
desc="[Vote](https://top.gg/bot/889078613817831495/vote) for me to get 25% more LCs!",
group="Economy",
aliases=('topgg', 'topggvote', 'upvote')
)
async def cmd_vote(ctx: LionContext):
"""
Usage``:
{prefix}vote
Description:
Get Top.gg bot's link for +25% Economy boost.
"""
embed = discord.Embed(
title="Claim your boost!",
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()
).set_thumbnail(
url="https://cdn.discordapp.com/attachments/908283085999706153/933012309532614666/lion-love.png"
)
return await ctx.reply(embed=embed, suggest_vote=False)
@module.cmd(
"vote_reminder",
group="Personal Settings",
desc="Turn on/off boost reminders."
)
async def cmd_remind_vote(ctx: LionContext):
"""
Usage:
`{prefix}vote_reminder on`
`{prefix}vote_reminder off`
Enable or disable DM boost reminders.
"""
await UserSettings.settings.vote_remainder.command(ctx, ctx.author.id)

View File

@@ -1,9 +0,0 @@
from data.interfaces import RowTable, Table
topggvotes = RowTable(
'topgg',
('voteid', 'userid', 'boostedTimestamp'),
'voteid'
)
guild_whitelist = Table('topgg_guild_whitelist')

View File

@@ -1,80 +0,0 @@
from LionModule import LionModule
from LionContext import LionContext
from core.lion import Lion
from modules.sponsors.module import sponsored_commands
from .utils import get_last_voted_timestamp, lion_loveemote, lion_yayemote
from .webhook import init_webhook
module = LionModule("Topgg")
upvote_info = "You have a boost available {}, to support our project and earn **25% more LionCoins** type `{}vote` {}"
@module.launch_task
async def attach_topgg_webhook(client):
if client.shard_id == 0:
init_webhook()
client.log("Attached top.gg voiting webhook.", context="TOPGG")
@module.launch_task
async def register_hook(client):
LionContext.reply.add_wrapper(topgg_reply_wrapper)
Lion.register_economy_bonus(economy_bonus)
client.log("Loaded top.gg hooks.", context="TOPGG")
@module.unload_task
async def unregister_hook(client):
Lion.unregister_economy_bonus(economy_bonus)
LionContext.reply.remove_wrapper(topgg_reply_wrapper.__name__)
client.log("Unloaded top.gg hooks.", context="TOPGG")
boostfree_groups = {'Meta'}
boostfree_commands = {'config', 'pomodoro'}
async def topgg_reply_wrapper(func, ctx: LionContext, *args, suggest_vote=True, **kwargs):
if not suggest_vote:
pass
elif not ctx.cmd:
pass
elif ctx.cmd.name in boostfree_commands or ctx.cmd.group in boostfree_groups:
pass
elif ctx.guild and ctx.guild.id in ctx.client.settings.topgg_guild_whitelist.value:
pass
elif ctx.guild and ctx.client.data.premium_guilds.queries.fetch_guild(ctx.guild.id):
pass
elif not get_last_voted_timestamp(ctx.author.id):
upvote_info_formatted = upvote_info.format(lion_yayemote, ctx.best_prefix, lion_loveemote)
if 'embed' in kwargs and ctx.cmd.name not in sponsored_commands:
# Add message as an extra embed field
kwargs['embed'].add_field(
name="\u200b",
value=(
upvote_info_formatted
),
inline=False
)
else:
# Add message to content
if 'content' in kwargs and kwargs['content']:
if len(kwargs['content']) + len(upvote_info_formatted) < 1998:
kwargs['content'] += '\n\n' + upvote_info_formatted
elif args:
if len(args[0]) + len(upvote_info_formatted) < 1998:
args = list(args)
args[0] += '\n\n' + upvote_info_formatted
else:
kwargs['content'] = upvote_info_formatted
return await func(ctx, *args, **kwargs)
def economy_bonus(lion):
return 1.25 if get_last_voted_timestamp(lion.userid) else 1

View File

@@ -1,72 +0,0 @@
from cmdClient.checks import is_owner
from settings import UserSettings, UserSetting, AppSettings
from settings.base import ListData, Setting
from settings.setting_types import Boolean, GuildIDList
from modules.reminders.reminder import Reminder
from modules.reminders.data import reminders
from .utils import create_remainder, remainder_content, topgg_upvote_link
from .data import guild_whitelist
@UserSettings.attach_setting
class topgg_vote_remainder(Boolean, UserSetting):
attr_name = 'vote_remainder'
_data_column = 'topgg_vote_reminder'
_default = True
display_name = 'vote_reminder'
desc = r"Toggle automatic reminders to support me for a 25% LionCoin boost."
long_desc = (
"Did you know that you can [vote for me]({vote_link}) to help me help other people reach their goals? "
"And you get a **25% boost** to all LionCoin income you make across all servers!\n"
"Enable this setting if you want me to let you know when you can vote again!"
).format(vote_link=topgg_upvote_link)
@property
def success_response(self):
if self.value:
# Check if reminder is already running
create_remainder(self.id)
return (
"Thank you for supporting me! I will remind in your DMs when you can vote next! "
"(Please make sure your DMs are open, otherwise I can't reach you!)"
)
else:
# Check if reminder is already running and get its id
r = reminders.select_one_where(
userid=self.id,
select_columns='reminderid',
content=remainder_content,
_extra="ORDER BY remind_at DESC LIMIT 1"
)
# Cancel and delete Remainder if already running
if r:
Reminder.delete(r['reminderid'])
return (
"I will no longer send you voting reminders."
)
@AppSettings.attach_setting
class topgg_guild_whitelist(GuildIDList, ListData, Setting):
attr_name = 'topgg_guild_whitelist'
write_ward = is_owner
category = 'Topgg Voting'
display_name = 'topgg_hidden_in'
desc = "Guilds where the topgg vote prompt is not displayed."
long_desc = (
"A list of guilds where the topgg vote prompt will be hidden."
)
_table_interface = guild_whitelist
_id_column = 'appid'
_data_column = 'guildid'
_force_unique = True

View File

@@ -1,97 +0,0 @@
import discord
import datetime
from meta import sharding
from meta import conf
from meta.client import client
from utils.lib import utc_now
from settings.setting_types import Integer
from modules.reminders.reminder import Reminder
from modules.reminders.data import reminders
from . import data as db
from data.conditions import GEQ
topgg_upvote_link = 'https://top.gg/bot/889078613817831495/vote'
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 = conf.emojis.getemoji('lionlove')
lion_yayemote = conf.emojis.getemoji('lionyay')
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(
userid=userid,
select_columns="boostedTimestamp",
boostedTimestamp=GEQ(utc_now() - datetime.timedelta(hours=12.5)),
_extra="ORDER BY boostedTimestamp DESC LIMIT 1"
)
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(
userid=userid,
content=remainder_content,
_extra="ORDER BY remind_at DESC LIMIT 1"
):
last_vote_time = get_last_voted_timestamp(userid)
# if no, Create reminder
reminder = Reminder.create(
userid=userid,
# TODO using content as a selector is not a good method
content=remainder_content,
message_link=None,
interval=None,
title="Your boost is now available! {}".format(lion_yayemote),
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
utc_now() + datetime.timedelta(minutes=5)
)
# remind_at=datetime.datetime.utcnow() + datetime.timedelta(minutes=2)
)
# Schedule reminder
if sharding.shard_number == 0:
reminder.schedule()
async def send_user_dm(userid):
# Send the message, if possible
if not (user := client.get_user(userid)):
try:
user = await client.fetch_user(userid)
except discord.HTTPException:
pass
if user:
try:
embed = discord.Embed(
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"
"Thank you for supporting us, enjoy your LionCoins boost!"
),
colour=discord.Colour.orange()
).set_image(
url="https://cdn.discordapp.com/attachments/908283085999706153/932737228440993822/lion-yay.png"
)
await user.send(embed=embed)
except discord.HTTPException:
# Nothing we can really do here. Maybe tell the user about their reminder next time?
pass

View File

@@ -1,40 +0,0 @@
from meta.client import client
from settings.user_settings import UserSettings
from utils.lib import utc_now
from meta.config import conf
import topgg
from .utils import db, send_user_dm, create_remainder
@client.event
async def on_dbl_vote(data):
"""An event that is called whenever someone votes for the bot on Top.gg."""
client.log(f"Received a vote: \n{data}", context='Topgg')
db.topggvotes.insert(
userid=data['user'],
boostedTimestamp=utc_now()
)
await send_user_dm(data['user'])
if UserSettings.settings.vote_remainder.value:
create_remainder(data['user'])
if data["type"] == "test":
return client.dispatch("dbl_test", data)
@client.event
async def on_dbl_test(data):
"""An event that is called whenever someone tests the webhook system for your bot on Top.gg."""
client.log(f"Received a test vote:\n{data}", context='Topgg')
def init_webhook():
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"))