Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
Remove topgg server voting as they don't have anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
wrkzdev committed Feb 18, 2024
1 parent ecb1efd commit 5bc1cf8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 479 deletions.
216 changes: 0 additions & 216 deletions wrkzcoin_tipbot/cogs/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,149 +813,6 @@ async def balance(
traceback.print_exc(file=sys.stdout)
await logchanbot(f"[ERROR] /guild balance with {ctx.guild.name} / {ctx.guild.id}")

@commands.has_permissions(administrator=True)
@guild.sub_command(
usage="guild votereward <amount> <coin/token> [channel]",
options=[
Option('amount', 'amount', OptionType.string, required=True),
Option('coin', 'coin', OptionType.string, required=True),
Option('channel', 'channel', OptionType.channel, required=True)
],
description="Set a reward when a user vote to your guild (topgg, ...)."
)
async def votereward(
self,
ctx,
amount: str,
coin: str,
channel: disnake.TextChannel
):

msg = f"{EMOJI_INFORMATION} {ctx.author.mention}, loading..."
await ctx.response.send_message(msg)

try:
self.bot.commandings.append((str(ctx.guild.id) if hasattr(ctx, "guild") and hasattr(ctx.guild, "id") else "DM",
str(ctx.author.id), SERVER_BOT, "/guild votereward", int(time.time())))
await self.utils.add_command_calls()
except Exception:
traceback.print_exc(file=sys.stdout)

# Check if channel is text channel
if type(channel) is not disnake.TextChannel:
msg = f'{ctx.author.mention}, that\'s not a text channel. Try a different channel!'
await ctx.edit_original_message(content=msg)
return

coin_name = coin.upper()
if len(self.bot.coin_alias_names) > 0 and coin_name in self.bot.coin_alias_names:
coin_name = self.bot.coin_alias_names[coin_name]
if not hasattr(self.bot.coin_list, coin_name):
await ctx.edit_original_message(content=f'{ctx.author.mention}, **{coin_name}** does not exist with us.')
return

net_name = getattr(getattr(self.bot.coin_list, coin_name), "net_name")
type_coin = getattr(getattr(self.bot.coin_list, coin_name), "type")
deposit_confirm_depth = getattr(getattr(self.bot.coin_list, coin_name), "deposit_confirm_depth")
token_display = getattr(getattr(self.bot.coin_list, coin_name), "display_name")
min_tip = getattr(getattr(self.bot.coin_list, coin_name), "real_min_tip")
max_tip = getattr(getattr(self.bot.coin_list, coin_name), "real_max_tip")
get_deposit = await self.wallet_api.sql_get_userwallet(
str(ctx.guild.id), coin_name, net_name, type_coin, SERVER_BOT, 0
)
if get_deposit is None:
get_deposit = await self.wallet_api.sql_register_user(
str(ctx.guild.id), coin_name, net_name, type_coin, SERVER_BOT, 0, 1
)

wallet_address = get_deposit['balance_wallet_address']
if type_coin in ["TRTL-API", "TRTL-SERVICE", "BCN", "XMR"]:
wallet_address = get_deposit['paymentid']
elif type_coin in ["XRP"]:
wallet_address = get_deposit['destination_tag']

height = await self.wallet_api.get_block_height(type_coin, coin_name, net_name)
userdata_balance = await self.wallet_api.user_balance(
str(ctx.guild.id), coin_name, wallet_address,
type_coin, height, deposit_confirm_depth, SERVER_BOT)
actual_balance = float(userdata_balance['adjust'])

amount = amount.replace(",", "")
amount = text_to_num(amount)
if amount is None:
msg = f'{EMOJI_RED_NO} {ctx.author.mention}, invalid given amount.'
await ctx.edit_original_message(content=msg)
return
# We assume max reward by max_tip / 10
elif amount < min_tip or amount > max_tip / 10:
msg = f"{EMOJI_RED_NO} {ctx.author.mention}, reward cannot be smaller than "\
f"{num_format_coin(min_tip)} {token_display} "\
f"or bigger than {num_format_coin(max_tip / 10)} {token_display}."
await ctx.edit_original_message(content=msg)
return
# We assume at least guild need to have 100x of reward or depends on guild's population
elif amount*100 > actual_balance:
msg = f"{EMOJI_RED_NO} {ctx.author.mention}, your guild needs to have at least 100x "\
f"reward balance. 100x rewards = {num_format_coin(amount*100)} "\
f"{token_display}. Check with {self.bot.config['command_list']['guild_balance']}."
await ctx.edit_original_message(content=msg)
return
elif amount*len(ctx.guild.members) > actual_balance:
population = len(ctx.guild.members)
msg = f"{EMOJI_RED_NO} {ctx.author.mention} you need to have at least {str(population)}x "\
f"reward balance. {str(population)}x rewards = "\
f"{num_format_coin(amount*population)} {token_display}."
await ctx.edit_original_message(content=msg)
return
else:
# Check channel
get_channel = self.bot.get_channel(int(channel.id))
channel_str = str(channel.id)
# Test message
msg = f"New vote reward set to {num_format_coin(amount)} {token_display}"\
f" by {ctx.author.name}#{ctx.author.discriminator} and message here."
try:
await get_channel.send(msg)
except Exception:
msg = f'{ctx.author.mention}, failed to message channel {channel.mention}. Set reward denied!'
await ctx.edit_original_message(content=msg)
traceback.print_exc(file=sys.stdout)
return

# Process, only guild owner can process
try:
serverinfo = self.bot.other_data['guild_list'].get(str(ctx.guild.id))
if serverinfo is None:
# Let's add some info if server return None
await store.sql_addinfo_by_server(str(ctx.guild.id), ctx.guild.name, "/", DEFAULT_TICKER)
# re-load guild list
await self.utils.bot_reload_guilds()
except Exception:
msg = f'{ctx.author.mention}, internal error. Please report.'
await ctx.edit_original_message(content=msg)
traceback.print_exc(file=sys.stdout)
update_reward = await self.update_reward(str(ctx.guild.id), float(amount), coin_name, False, channel_str)
if update_reward > 0:
msg = f"{ctx.author.mention} Successfully set reward for voting in guild {ctx.guild.name} to "\
f"{num_format_coin(amount)} {token_display}."
await ctx.edit_original_message(content=msg)
try:
await self.vote_logchan(
f"[{SERVER_BOT}] A user {ctx.author.name}#{ctx.author.discriminator} "\
f"set a vote reward in guild {ctx.guild.name} / {ctx.guild.id} to "\
f"{num_format_coin(amount)} {token_display}."
)
except Exception:
traceback.print_exc(file=sys.stdout)
else:
msg = f'{ctx.author.mention}, internal error or nothing updated.'
await ctx.edit_original_message(content=msg)

@votereward.autocomplete("coin")
async def votereward_token_name_autocomp(self, inter: disnake.CommandInteraction, string: str):
string = string.lower()
return [name for name in self.bot.coin_name_list if string in name.lower()][:10]

@guild.sub_command(
usage="guild deposit <amount> <coin/token>",
options=[
Expand Down Expand Up @@ -1154,79 +1011,6 @@ async def guilddeposit_token_name_autocomp(self, inter: disnake.CommandInteracti
string = string.lower()
return [name for name in self.bot.coin_name_list if string in name.lower()][:10]

@commands.has_permissions(administrator=True)
@guild.sub_command(
usage="guild topgg [resetkey]",
options=[
Option('resetkey', 'resetkey', OptionType.string, required=False, choices=[
OptionChoice("YES", "YES"),
OptionChoice("NO", "NO")
])
],
description="Get token key to set for topgg vote in bot channel."
)
async def topgg(
self,
ctx,
resetkey: str=None
):
msg = f"{EMOJI_INFORMATION} {ctx.author.mention}, loading..."
await ctx.response.send_message(msg, ephemeral=True)

try:
self.bot.commandings.append((str(ctx.guild.id) if hasattr(ctx, "guild") and hasattr(ctx.guild, "id") else "DM",
str(ctx.author.id), SERVER_BOT, "/guild topgg", int(time.time())))
await self.utils.add_command_calls()
except Exception:
traceback.print_exc(file=sys.stdout)

secret = "topgg_vote_secret"
if resetkey is None: resetkey = "NO"
get_guild_by_key = await self.guild_find_by_key(str(ctx.guild.id), secret)
if get_guild_by_key is None:
# Generate
random_string = str(uuid.uuid4())
insert_key = await self.guild_insert_key(str(ctx.guild.id), random_string, secret, False)
if insert_key:
try:
await ctx.edit_original_message(
content=f"Your guild {ctx.guild.name}\'s topgg key: __{random_string}__\nWebook URL: "\
f"__{self.bot.config['topgg']['guild_vote_url']}__"
)
except Exception:
traceback.print_exc(file=sys.stdout)
else:
try:
await ctx.edit_original_message(content=f'Internal error! Please report!')
except Exception:
traceback.print_exc(file=sys.stdout)
elif get_guild_by_key and resetkey == "NO":
# Just display
try:
await ctx.edit_original_message(
content=f"Your guild {ctx.guild.name}\'s topgg key: __{get_guild_by_key}__\n"\
f"Webook URL: __{self.bot.config['topgg']['guild_vote_url']}__"
)
except Exception:
traceback.print_exc(file=sys.stdout)
elif get_guild_by_key and resetkey == "YES":
# Update a new key and say to it. Do not forget to update
random_string = str(uuid.uuid4())
insert_key = await self.guild_insert_key(str(ctx.guild.id), random_string, secret, True)
if insert_key:
try:
await ctx.edit_original_message(
content=f"Your guild {ctx.guild.name}\'s topgg updated key: __{random_string}__\n"\
f"Webook URL: __{self.bot.config['topgg']['guild_vote_url']}__"
)
except Exception:
traceback.print_exc(file=sys.stdout)
else:
try:
await ctx.edit_original_message(content=f'Internal error! Please report!')
except Exception:
traceback.print_exc(file=sys.stdout)

# Guild deposit
async def async_mdeposit(self, ctx, token: str=None, plain: str=None):
msg = f"{EMOJI_INFORMATION} {ctx.author.mention}, loading..."
Expand Down
Loading

0 comments on commit 5bc1cf8

Please sign in to comment.