2023-03-05 22:53:54 -05:00
import discord
from redbot . core import commands , bank , checks
2023-03-05 22:55:04 -05:00
class SugonCredit ( commands . Cog ) :
2023-03-05 22:53:54 -05:00
""" Implements a way for moderators to give out social-credit like points, dubbed ' sugoncredits ' by the community. """
def __init__ ( self , bot ) :
self . bot = bot
@commands.group ( autohelp = True , aliases = [ " sugoncredit " ] )
@commands.guild_only ( )
2023-03-05 22:56:00 -05:00
async def credit ( self , ctx ) :
2023-03-05 22:53:54 -05:00
""" Simple points system. """
@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
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 { 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 { bal } { currency_name } s. " )
await ctx . send ( embed = embed )
@credit.command ( )
@commands.guild_only ( )
@commands.mod ( )
async def add ( self , ctx , target : discord . Member , amount : int ) :
""" Adds credits to an account. """
2023-03-05 23:24:13 -05:00
try :
val = int ( amount )
except ValueError :
await ctx . send ( content = " ``amount`` must be a number! Please try again. " )
return
2023-03-05 22:53:54 -05:00
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 )
new_bal = current_bal + amount
if new_bal > max_bal :
await ctx . send ( content = f " You are attempting to set { target . mention } ' s balance to above { max . bal } . Please try again! " )
return
2023-03-05 23:24:13 -05:00
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
2023-03-05 22:53:54 -05:00
else :
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 { amount } . \n Current balance is { new_bal } . " )
2023-03-05 22:58:41 -05:00
await bank . deposit_credits ( target , amount = amount )
2023-03-05 22:53:54 -05:00
await ctx . send ( embed = embed )
@credit.command ( )
@commands.guild_only ( )
@commands.mod ( )
async def remove ( self , ctx , target : discord . Member , amount : int ) :
""" Removes credits from an account. """
2023-03-05 23:24:13 -05:00
try :
val = int ( amount )
except ValueError :
await ctx . send ( content = " ``amount`` must be a number. Please try again! " )
return
2023-03-05 22:53:54 -05:00
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 )
new_bal = current_bal - amount
2023-03-05 23:24:13 -05:00
if new_bal < 0 :
await ctx . send ( content = f " You are attempting to set { target . mention } ' s balance to below 0. Please try again! " )
2023-03-05 22:53:54 -05:00
return
else :
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 { amount } . \n Current balance is { new_bal } . " )
2023-03-05 22:58:41 -05:00
await bank . withdraw_credits ( target , amount = amount )
2023-03-05 22:53:54 -05:00
await ctx . send ( embed = embed )