Compare commits

...

24 commits

Author SHA1 Message Date
56e4e8fe7c
fix: fixed requirements 2023-08-07 17:56:23 -04:00
34a9759a67
feat: discord.py 2.0 compat 2023-08-07 17:56:19 -04:00
09bdf4768e
fix: fixed new_guild_generation again 2023-08-01 18:09:07 -04:00
78ce22aa72
fixed new_guild_generation being called improperly 2023-08-01 18:06:54 -04:00
3af564f9cd
fix: changing stuff in the new_guild_generation method 2023-08-01 18:05:49 -04:00
074569465b
cleanup: removed useless variable 2023-08-01 18:04:03 -04:00
53d1d20942
fix: refactored new_guild_generation 2023-08-01 18:03:45 -04:00
b0c32a130b
fix: no longer using inflect 2023-08-01 17:58:31 -04:00
8759ee1820
fix: added dependency requirement to info.json 2023-08-01 17:52:56 -04:00
d51f42289b
feat: refactored balance command 2023-08-01 17:52:14 -04:00
2173998ced
fix: removing useless data 2023-08-01 17:37:25 -04:00
SeaswimmerTheFsh
6c150045f5 making sure galaxy.py is updated on this 2023-03-16 17:04:11 -04:00
SeaswimmerTheFsh
b241606796 Update sugoncredit.py 2023-03-16 16:30:22 -04:00
SeaswimmerTheFsh
2169436a70 Update sugoncredit.py 2023-03-15 11:59:46 -04:00
SeaswimmerTheFsh
691cacbbc6 Update sugoncredit.py 2023-03-15 11:45:11 -04:00
SeaswimmerTheFsh
22d9802aa0 fixed a bunch of goofy aah formatting 2023-03-14 22:46:45 -04:00
SeaswimmerTheFsh
680759c5dd WOOOOOO im going insane
changed a bunch of sql stuff
2023-03-14 22:45:13 -04:00
SeaswimmerTheFsh
5aebdc5eed global --> guild 2023-03-14 20:05:21 -04:00
SeaswimmerTheFsh
019f68a1e8 added another check
credit add and credit remove will now check if the new balance is below the minimum balance - on that note, added min_bal as a config option
2023-03-14 19:49:55 -04:00
SeaswimmerTheFsh
8f9c774f68 removed negative check
removed the if statement that checked if the new balance being set was below 0. this allows balances to go below 0
2023-03-14 19:45:50 -04:00
SeaswimmerTheFsh
6c3a7d1e78 Update sugoncredit.py
doing more sql stuff
2023-03-14 19:42:44 -04:00
SeaswimmerTheFsh
6d41ea67e2 Update galaxy.py
made sure galaxy.py is identical to the main branch version in sugoncredit_sql
2023-03-14 18:29:25 -04:00
SeaswimmerTheFsh
87ea3b273e removed import
removed re from imports in galaxy.py as it isn't used
2023-03-14 18:21:45 -04:00
e5656d2aa2 sql version pushed 2023-03-13 21:39:51 -04:00
5 changed files with 163 additions and 35 deletions

2
.gitignore vendored
View file

@ -3,3 +3,5 @@ galaxy_server.yaml
global.yaml global.yaml
galaxy_staff_server.yaml galaxy_staff_server.yaml
combat_welder.yaml combat_welder.yaml
.venv
/OOUCogs

View file

@ -15,6 +15,36 @@ class Galaxy(commands.Cog):
cocoemoji = 1028535684757209118 cocoemoji = 1028535684757209118
) )
@commands.command(aliases=["pxc", "pc", "polarisconvert", "tatsutopolaris", "ttp"])
@commands.guild_only()
async def polarisxpconvert(self, ctx, *, tatsu_studs: str):
"""Converts Tatsu Studs to Polaris XP."""
try:
tatsu_studs_int = int(f"{tatsu_studs}".replace(",", ""))
except ValueError:
await ctx.send(content="Please input a number!")
return
math = round((tatsu_studs_int/25)*10)
output_from = f'{tatsu_studs_int:,}'
output_to = f'{math:,}'
embed = discord.Embed(color=await self.bot.get_embed_color(None))
embed.add_field(name="Tatsu Studs", value=f"{output_from}", inline=False)
embed.add_field(name="Polaris XP", value=f"{output_to}", inline=False)
await ctx.send(embed=embed)
@commands.command()
async def galaxyissues(self, ctx, target: discord.Member = None):
if ctx.me.id == 1070819799254438039:
embed = discord.Embed(title="Issue Reporting & Suggestions", color=await self.bot.get_embed_color(None), description="Have a problem or a suggestion for the Galaxy bot or GalaxyCogs? Read this!")
embed.add_field(name="Bot Issues & Suggestions", value="If you'd like to submit a suggestion or a bug report to the developers of the Galaxy bot, please do so [here](https://github.com/SeaswimmerTheFsh/GalaxyCogs/issues).\n**Please make sure whatever you're suggesting or reporting doesn't have an existing issue! If it does, you can comment on that issue with additional details if necessary.**")
else:
embed = discord.Embed(title="Issue Reporting & Suggestions", color=await self.bot.get_embed_color(None), description="Have a problem or a suggestion for GalaxyCogs? Read this!")
embed.add_field(name="Cog Issues & Suggestions", value="If you'd like to submit a suggestion or a bug report to the developers of GalaxyCogs, please do so [here](https://github.com/SeaswimmerTheFsh/GalaxyCogs/issues).\n**Please make sure whatever you're suggesting or reporting doesn't have an existing issue! If it does, you can comment on that issue with additional details if necessary.**")
if target:
await ctx.send(embed=embed, content=f"{target.mention}")
else:
await ctx.send(embed=embed)
@commands.command() @commands.command()
async def lwaccess(self, ctx): async def lwaccess(self, ctx):
"""You shouldn't be able to see this!""" """You shouldn't be able to see this!"""

View file

@ -1,5 +1,5 @@
from .sugoncredit import SugonCredit from .sugoncredit import SugonCredit
def setup(bot): async def setup(bot):
bot.add_cog(SugonCredit(bot)) await bot.add_cog(SugonCredit(bot))

View file

@ -5,5 +5,6 @@
"short" : "Simple points system.", "short" : "Simple points system.",
"description" : "Implements a way for moderators to give out social-credit like points, dubbed 'sugoncredits' by the community.", "description" : "Implements a way for moderators to give out social-credit like points, dubbed 'sugoncredits' by the community.",
"tags" : ["bank"], "tags" : ["bank"],
"end_user_data_statement": "This cog stores no end user data." "end_user_data_statement": "This cog stores no end user data.",
"requirements": ["inflect", "tabulate"]
} }

View file

@ -1,34 +1,102 @@
import sqlite3
from sqlite3 import Error
import discord 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): class SugonCredit(commands.Cog):
"""Implements a way for moderators to give out social-credit like points, dubbed 'sugoncredits' by the community.""" """Implements a way for moderators to give out social-credit like points, dubbed 'sugoncredits' by the community."""
def __init__(self, bot): def __init__(self, bot):
self.bot = 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.group(autohelp=True, aliases=["sugoncredit"])
@commands.guild_only() @commands.guild_only()
async def credit(self, ctx): async def credit(self, ctx):
"""Simple points system.""" """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() @credit.command()
@commands.guild_only() @commands.guild_only()
async def balance(self, ctx, user: discord.Member = None): async def balance(self, ctx, user: discord.Member = None):
"""Checks an account's balance.""" """Checks an account's balance."""
bank_name = await bank.get_bank_name(ctx.guild) target = user if user else ctx.author
currency_name = await bank.get_currency_name(ctx.guild) con = sqlite3.connect(self.data_path)
if user == None: cur = con.cursor()
bal = await bank.get_balance(ctx.author) await self.new_guild_generation(ctx.guild.id)
target = ctx.author bank_name = await self.config.guild(ctx.guild).get_raw('bank_name', default="Bank")
else: currency_name = await self.config.guild(ctx.guild).get_raw('currency_name', default="Credit")
bal = await bank.get_balance(user) cur.execute(f"SELECT user_id FROM {ctx.guild.id} WHERE user_id = ?;", (target.id,))
target = user if not cur.fetchone():
output_bal = (f'{bal:,}') await self.new_user_generation(ctx.guild.id, target)
if bal == 1 or bal == -1: cur.execute(f"SELECT balance FROM {ctx.guild.id} WHERE user_id = ?;", (target.id,))
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}.") bal = cur.fetchone()[0]
else: output_bal = f'{bal:,}'
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.") 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) await ctx.send(embed=embed)
con.close()
@credit.command() @credit.command()
@commands.guild_only() @commands.guild_only()
@ -40,24 +108,31 @@ class SugonCredit(commands.Cog):
except ValueError: except ValueError:
await ctx.send(content="``amount`` must be a number! Please try again.") await ctx.send(content="``amount`` must be a number! Please try again.")
return 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") image = discord.File(fp=data_manager.bundled_data_path(self) / "add.png", filename="Add.png")
bank_name = await bank.get_bank_name(ctx.guild) bank_name = await self.config.bank_name()
currency_name = await bank.get_currency_name(ctx.guild) currency_name = await self.config.currency_name()
current_bal = await bank.get_balance(target) max_bal = await self.config.max_bal()
max_bal = await bank.get_max_balance(ctx.guild) 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 new_bal = current_bal + amount
output_amount = (f'{val:,}') output_amount = (f'{val:,}')
output_new_bal = (f'{new_bal:,}') output_new_bal = (f'{new_bal:,}')
output_max_bal = (f'{max_bal:,}') output_max_bal = (f'{max_bal:,}')
output_min_bal = (f'{min_bal:,}')
if new_bal > max_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!") await ctx.send(content=f"You are attempting to set {target.mention}'s balance to above {output_max_bal}. Please try again!")
return return
elif new_bal < 0: elif new_bal < min_bal:
await ctx.send(content=f"You are attempting to set {target.mention}'s balance to below 0. Please try again!") await ctx.send(content=f"You are attempting to set {target.mention}'s balance to below {output_min_bal}. Please try again!")
return
elif ctx.guild.id == 204965774618656769: elif ctx.guild.id == 204965774618656769:
logging_channel = self.bot.get_channel(1082495815878189076) 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}!") 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: 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) 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) await logging_channel.send(embed=logging_embed)
elif ctx.guild.id != 204965774618656769: 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}.") 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) await ctx.send(embed=embed)
con.commit()
con.close()
@credit.command() @credit.command()
@commands.guild_only() @commands.guild_only()
@ -81,17 +160,29 @@ class SugonCredit(commands.Cog):
await ctx.send(content="``amount`` must be a number. Please try again!") await ctx.send(content="``amount`` must be a number. Please try again!")
return return
image = discord.File(fp=data_manager.bundled_data_path(self) / "remove.mp4", filename="MEGA_BASE.mp4") 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) data_path = data_manager.cog_data_path(self) / "credit.db"
currency_name = await bank.get_currency_name(ctx.guild) con = sqlite3.connect(f'{data_path}')
current_bal = await bank.get_balance(target) 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 new_bal = current_bal - amount
output_amount = (f'{val:,}') output_amount = (f'{val:,}')
output_new_bal = (f'{new_bal:,}') output_new_bal = (f'{new_bal:,}')
if new_bal < 0: output_max_bal = (f'{max_bal:,}')
await ctx.send(content=f"You are attempting to set {target.mention}'s balance to below 0. Please try again!") output_min_bal = (f'{min_bal:,}')
return 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: 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) 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!") 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: if amount == 1 or amount == -1:
@ -103,4 +194,8 @@ class SugonCredit(commands.Cog):
elif ctx.guild.id != 204965774618656769: 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}.") 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 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()