|
|
|
@ -1,34 +1,102 @@
|
|
|
|
|
import sqlite3
|
|
|
|
|
from sqlite3 import Error
|
|
|
|
|
import discord
|
|
|
|
|
from redbot.core import commands, bank, checks, data_manager
|
|
|
|
|
from redbot.core import Config, checks, commands, data_manager
|
|
|
|
|
from tabulate import tabulate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SugonCredit(commands.Cog):
|
|
|
|
|
"""Implements a way for moderators to give out social-credit like points, dubbed 'sugoncredits' by the community."""
|
|
|
|
|
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
|
self.bot = bot
|
|
|
|
|
self.config = Config.get_conf(self, identifier=47252584)
|
|
|
|
|
self.config.register_guild(
|
|
|
|
|
bank_name = "Social Credit Enforcement Agency",
|
|
|
|
|
currency_name = "Social Credit",
|
|
|
|
|
max_bal = 1000000000,
|
|
|
|
|
min_bal = -1000000000
|
|
|
|
|
)
|
|
|
|
|
self.data_path = data_manager.cog_data_path(self) / "credit.db"
|
|
|
|
|
con = sqlite3.connect(f'{self.data_path}')
|
|
|
|
|
con.commit()
|
|
|
|
|
con.close()
|
|
|
|
|
|
|
|
|
|
def pluralize(word, count):
|
|
|
|
|
if count == 1:
|
|
|
|
|
return word
|
|
|
|
|
elif word.endswith('s') or word.endswith('x') or word.endswith('z') or word.endswith('ch') or word.endswith('sh'):
|
|
|
|
|
return word + 'es'
|
|
|
|
|
elif word.endswith('y'):
|
|
|
|
|
# Change 'y' to 'ies' for words ending with a consonant + 'y'
|
|
|
|
|
return word[:-1] + 'ies'
|
|
|
|
|
else:
|
|
|
|
|
return word + 's'
|
|
|
|
|
|
|
|
|
|
def new_guild_generation(self, guild_id):
|
|
|
|
|
"""Adds a new table for a guild to the SQLite database."""
|
|
|
|
|
con = sqlite3.connect(self.data_path)
|
|
|
|
|
cur = con.cursor()
|
|
|
|
|
try:
|
|
|
|
|
cur.execute(f"SELECT 1 FROM '{guild_id}' LIMIT 1;")
|
|
|
|
|
except sqlite3.OperationalError:
|
|
|
|
|
cur.execute(f"CREATE TABLE '{guild_id}' (user_id TEXT, balance REAL);")
|
|
|
|
|
con.commit()
|
|
|
|
|
con.close()
|
|
|
|
|
|
|
|
|
|
def new_user_generation(self, guild_id, target):
|
|
|
|
|
"""Adds a new user to the SQLite database."""
|
|
|
|
|
con = sqlite3.connect(f'{self.data_path}')
|
|
|
|
|
cur = con.cursor()
|
|
|
|
|
cur.execute(f'''INSERT INTO {guild_id}
|
|
|
|
|
VALUES ({target.id}, 250);''')
|
|
|
|
|
con.commit()
|
|
|
|
|
con.close()
|
|
|
|
|
|
|
|
|
|
@commands.group(autohelp=True, aliases=["sugoncredit"])
|
|
|
|
|
@commands.guild_only()
|
|
|
|
|
async def credit(self, ctx):
|
|
|
|
|
"""Simple points system."""
|
|
|
|
|
|
|
|
|
|
@credit.command()
|
|
|
|
|
@commands.guild_only()
|
|
|
|
|
async def leaderboard(self, ctx, page: int = 1):
|
|
|
|
|
"""Shows the individuals with the highest balances."""
|
|
|
|
|
await ctx.send(content="This command isn't done yet!")
|
|
|
|
|
con = sqlite3.connect(f'{self.data_path}')
|
|
|
|
|
cur = con.cursor()
|
|
|
|
|
await self.new_guild_generation(self, ctx.guild.id)
|
|
|
|
|
bank_name = await self.config.guild(ctx.guild).bank_name()
|
|
|
|
|
currency_name = await self.config.guild(ctx.guild).currency_name()
|
|
|
|
|
offset = (page - 1) * 10
|
|
|
|
|
raw_list = cur.execute(f'''SELECT user_id, balance FROM {ctx.guild.id}
|
|
|
|
|
ORDER BY balance DESC
|
|
|
|
|
LIMIT 10 OFFSET {offset};''')
|
|
|
|
|
await ctx.send(content=f"{raw_list}")
|
|
|
|
|
|
|
|
|
|
@credit.command()
|
|
|
|
|
@commands.guild_only()
|
|
|
|
|
async def balance(self, ctx, user: discord.Member = None):
|
|
|
|
|
"""Checks an account's balance."""
|
|
|
|
|
bank_name = await bank.get_bank_name(ctx.guild)
|
|
|
|
|
currency_name = await bank.get_currency_name(ctx.guild)
|
|
|
|
|
if user == None:
|
|
|
|
|
bal = await bank.get_balance(ctx.author)
|
|
|
|
|
target = ctx.author
|
|
|
|
|
else:
|
|
|
|
|
bal = await bank.get_balance(user)
|
|
|
|
|
target = user
|
|
|
|
|
output_bal = (f'{bal:,}')
|
|
|
|
|
if bal == 1 or bal == -1:
|
|
|
|
|
embed=discord.Embed(title=f"{bank_name} - Balance", color=await self.bot.get_embed_color(None), description=f"{target.mention} has {output_bal} {currency_name}.")
|
|
|
|
|
else:
|
|
|
|
|
embed=discord.Embed(title=f"{bank_name} - Balance", color=await self.bot.get_embed_color(None), description=f"{target.mention} has {output_bal} {currency_name}s.")
|
|
|
|
|
target = user if user else ctx.author
|
|
|
|
|
con = sqlite3.connect(self.data_path)
|
|
|
|
|
cur = con.cursor()
|
|
|
|
|
await self.new_guild_generation(ctx.guild.id)
|
|
|
|
|
bank_name = await self.config.guild(ctx.guild).get_raw('bank_name', default="Bank")
|
|
|
|
|
currency_name = await self.config.guild(ctx.guild).get_raw('currency_name', default="Credit")
|
|
|
|
|
cur.execute(f"SELECT user_id FROM {ctx.guild.id} WHERE user_id = ?;", (target.id,))
|
|
|
|
|
if not cur.fetchone():
|
|
|
|
|
await self.new_user_generation(ctx.guild.id, target)
|
|
|
|
|
cur.execute(f"SELECT balance FROM {ctx.guild.id} WHERE user_id = ?;", (target.id,))
|
|
|
|
|
bal = cur.fetchone()[0]
|
|
|
|
|
output_bal = f'{bal:,}'
|
|
|
|
|
pluralized_currency_name = await self.pluralize(currency_name, bal)
|
|
|
|
|
embed_title = f"{bank_name} - Balance"
|
|
|
|
|
embed_color = await self.bot.get_embed_color(None)
|
|
|
|
|
embed_description = f"{target.mention} has {output_bal} {pluralized_currency_name}."
|
|
|
|
|
embed = discord.Embed(title=embed_title, color=embed_color, description=embed_description)
|
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
con.close()
|
|
|
|
|
|
|
|
|
|
@credit.command()
|
|
|
|
|
@commands.guild_only()
|
|
|
|
@ -40,24 +108,31 @@ class SugonCredit(commands.Cog):
|
|
|
|
|
except ValueError:
|
|
|
|
|
await ctx.send(content="``amount`` must be a number! Please try again.")
|
|
|
|
|
return
|
|
|
|
|
con = sqlite3.connect(f'{self.data_path}')
|
|
|
|
|
cur = con.cursor()
|
|
|
|
|
await self.new_guild_generation({ctx.guild.id})
|
|
|
|
|
image = discord.File(fp=data_manager.bundled_data_path(self) / "add.png", filename="Add.png")
|
|
|
|
|
bank_name = await bank.get_bank_name(ctx.guild)
|
|
|
|
|
currency_name = await bank.get_currency_name(ctx.guild)
|
|
|
|
|
current_bal = await bank.get_balance(target)
|
|
|
|
|
max_bal = await bank.get_max_balance(ctx.guild)
|
|
|
|
|
bank_name = await self.config.bank_name()
|
|
|
|
|
currency_name = await self.config.currency_name()
|
|
|
|
|
max_bal = await self.config.max_bal()
|
|
|
|
|
min_bal = await self.config_min_bal()
|
|
|
|
|
current_bal = cur.execute(f'''SELECT balance FROM {ctx.guild.id}
|
|
|
|
|
WHERE user_id = {target.id};''')
|
|
|
|
|
new_bal = current_bal + amount
|
|
|
|
|
output_amount = (f'{val:,}')
|
|
|
|
|
output_new_bal = (f'{new_bal:,}')
|
|
|
|
|
output_max_bal = (f'{max_bal:,}')
|
|
|
|
|
output_min_bal = (f'{min_bal:,}')
|
|
|
|
|
if new_bal > max_bal:
|
|
|
|
|
await ctx.send(content=f"You are attempting to set {target.mention}'s balance to above {output_max_bal}. Please try again!")
|
|
|
|
|
return
|
|
|
|
|
elif new_bal < 0:
|
|
|
|
|
await ctx.send(content=f"You are attempting to set {target.mention}'s balance to below 0. Please try again!")
|
|
|
|
|
return
|
|
|
|
|
elif new_bal < min_bal:
|
|
|
|
|
await ctx.send(content=f"You are attempting to set {target.mention}'s balance to below {output_min_bal}. Please try again!")
|
|
|
|
|
elif ctx.guild.id == 204965774618656769:
|
|
|
|
|
logging_channel = self.bot.get_channel(1082495815878189076)
|
|
|
|
|
await bank.deposit_credits(target, amount=amount)
|
|
|
|
|
cur.execute(f'''UPDATE {ctx.guild.id}
|
|
|
|
|
SET balance = {new_bal}
|
|
|
|
|
WHERE user_id = {target.id};''')
|
|
|
|
|
await ctx.send(content=f"{target.mention} now has {output_amount} more SugonCredit, with a total of {output_new_bal}!")
|
|
|
|
|
if amount == 1 or amount == -1:
|
|
|
|
|
await target.send(content=f"You gained {output_amount} SugonCredit! Good work community member! You now have {output_new_bal} SugonCredits.", file=image)
|
|
|
|
@ -67,8 +142,12 @@ class SugonCredit(commands.Cog):
|
|
|
|
|
await logging_channel.send(embed=logging_embed)
|
|
|
|
|
elif ctx.guild.id != 204965774618656769:
|
|
|
|
|
embed=discord.Embed(title=f"{bank_name} - Add", color=await self.bot.get_embed_color(None), description=f"{target.mention}'s {currency_name} balance has been increased by {output_amount}.\nCurrent balance is {output_new_bal}.")
|
|
|
|
|
await bank.deposit_credits(target, amount=amount)
|
|
|
|
|
cur.execute(f'''UPDATE {ctx.guild.id}
|
|
|
|
|
SET balance = {new_bal}
|
|
|
|
|
WHERE user_id = {target.id};''')
|
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
con.commit()
|
|
|
|
|
con.close()
|
|
|
|
|
|
|
|
|
|
@credit.command()
|
|
|
|
|
@commands.guild_only()
|
|
|
|
@ -81,17 +160,29 @@ class SugonCredit(commands.Cog):
|
|
|
|
|
await ctx.send(content="``amount`` must be a number. Please try again!")
|
|
|
|
|
return
|
|
|
|
|
image = discord.File(fp=data_manager.bundled_data_path(self) / "remove.mp4", filename="MEGA_BASE.mp4")
|
|
|
|
|
bank_name = await bank.get_bank_name(ctx.guild)
|
|
|
|
|
currency_name = await bank.get_currency_name(ctx.guild)
|
|
|
|
|
current_bal = await bank.get_balance(target)
|
|
|
|
|
data_path = data_manager.cog_data_path(self) / "credit.db"
|
|
|
|
|
con = sqlite3.connect(f'{data_path}')
|
|
|
|
|
cur = con.cursor()
|
|
|
|
|
await self.new_guild_generation({ctx.guild.id})
|
|
|
|
|
bank_name = await self.config.bank_name()
|
|
|
|
|
currency_name = await self.config.currency_name()
|
|
|
|
|
max_bal = await self.config.max_bal()
|
|
|
|
|
min_bal = await self.config_min_bal()
|
|
|
|
|
current_bal = cur.execute(f'''SELECT balance FROM {ctx.guild.id}
|
|
|
|
|
WHERE user_id = {target.id};''')
|
|
|
|
|
new_bal = current_bal - amount
|
|
|
|
|
output_amount = (f'{val:,}')
|
|
|
|
|
output_new_bal = (f'{new_bal:,}')
|
|
|
|
|
if new_bal < 0:
|
|
|
|
|
await ctx.send(content=f"You are attempting to set {target.mention}'s balance to below 0. Please try again!")
|
|
|
|
|
return
|
|
|
|
|
output_max_bal = (f'{max_bal:,}')
|
|
|
|
|
output_min_bal = (f'{min_bal:,}')
|
|
|
|
|
if new_bal > max_bal:
|
|
|
|
|
await ctx.send(content=f"You are attempting to set {target.mention}'s balance to above {output_max_bal}. Please try again!")
|
|
|
|
|
elif new_bal < min_bal:
|
|
|
|
|
await ctx.send(content=f"You are attempting to set {target.mention}'s balance to below {output_min_bal}. Please try again!")
|
|
|
|
|
elif ctx.guild.id == 204965774618656769:
|
|
|
|
|
await bank.withdraw_credits(target, amount=amount)
|
|
|
|
|
cur.execute(f'''UPDATE {ctx.guild.id}
|
|
|
|
|
SET balance = {new_bal}
|
|
|
|
|
WHERE user_id = {target.id};''')
|
|
|
|
|
logging_channel = self.bot.get_channel(1082495815878189076)
|
|
|
|
|
await ctx.send(content=f"{target.mention} now has {output_amount} less SugonCredit, with a total of {output_new_bal}!\nIf this is a punishment, do better Galaxy Player! Re-education mods will be sent to your DM's if your SugonCredit drops to a substantially low amount!")
|
|
|
|
|
if amount == 1 or amount == -1:
|
|
|
|
@ -103,4 +194,8 @@ class SugonCredit(commands.Cog):
|
|
|
|
|
elif ctx.guild.id != 204965774618656769:
|
|
|
|
|
embed=discord.Embed(title=f"{bank_name} - Remove", color=await self.bot.get_embed_color(None), description=f"{target.mention}'s {currency_name} balance has been decreased by {output_amount}.\nCurrent balance is {output_new_bal}.")
|
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
await bank.withdraw_credits(target, amount=val)
|
|
|
|
|
cur.execute(f'''UPDATE {ctx.guild.id}
|
|
|
|
|
SET balance = {new_bal}
|
|
|
|
|
WHERE user_id = {target.id};''')
|
|
|
|
|
con.commit()
|
|
|
|
|
con.close()
|
|
|
|
|