palmtree5 4923ffe98a [Economy] [WIP] rewrite (#781)
* [Economy][Bank] redo branch

* WIP

WIP

* Implement all current bank commands API calls

* Set dunder all and put into bot

* make core change to economy

* Add is_global method to bank

WIP

* Add extra bank API commands

* Update bank UI

Update some imports

Remove bank UI errors file

Typing thing

* Update bank get_global_accounts and touch up economy some more

Do some more economy updates

* Remove bank from bot

* Another passing test

FINALLY

* Fixy type things

Last fixes for now

Fix arg to toggle global

RJM

Invalid bid amount handler

cooldown msg

currency name fix

Fix fun bug

ANother bug

And payday limit

* PEP8 stuff

* Docstring change

* Fix this thing

* [Economy][Bank] redo branch

* [Economy][Bank] modify guild owner or bot owner check, add admin or bot owner check for global vs local bank

* [Economy] apply admin or bot owner check to [p]economyset

* Make some public things private

* [Economy] lots of refactoring for conditional permission checks and guild checks + supporting global economy

* And working stuff

* Fix Kowlin's bug

* Fix slot bugs
2017-08-09 17:23:41 -08:00

68 lines
2.1 KiB
Python

from discord.ext import commands
from core import checks, bank
from core.bot import Red # Only used for type hints
def check_global_setting_guildowner():
async def pred(ctx: commands.Context):
if bank.is_global():
return checks.is_owner()
else:
return checks.guildowner_or_permissions(administrator=True)
return commands.check(pred)
def check_global_setting_admin():
async def pred(ctx: commands.Context):
if bank.is_global():
return checks.is_owner()
else:
return checks.admin_or_permissions(manage_guild=True)
return commands.check(pred)
class Bank:
"""Bank"""
def __init__(self, bot: Red):
self.bot = bot
# SECTION commands
@commands.group()
@checks.guildowner_or_permissions(administrator=True)
async def bankset(self, ctx: commands.Context):
"""Base command for bank settings"""
if ctx.invoked_subcommand is None:
await self.bot.send_cmd_help(ctx)
@bankset.command(name="toggleglobal")
@checks.is_owner()
async def bankset_toggleglobal(self, ctx: commands.Context):
"""Toggles whether the bank is global or not
If the bank is global, it will become per-guild
If the bank is per-guild, it will become global"""
cur_setting = bank.is_global()
await bank.set_global(not cur_setting, ctx.author)
word = "per-guild" if cur_setting else "global"
await ctx.send("The bank is now {}.".format(word))
@bankset.command(name="bankname")
@check_global_setting_guildowner()
async def bankset_bankname(self, ctx: commands.Context, *, name: str):
"""Set the bank's name"""
await bank.set_bank_name(name, ctx.guild)
await ctx.send("Bank's name has been set to {}".format(name))
@bankset.command(name="creditsname")
@check_global_setting_guildowner()
async def bankset_creditsname(self, ctx: commands.Context, *, name: str):
"""Set the name for the bank's currency"""
await bank.set_currency_name(name, ctx.guild)
await ctx.send("Currency name has been set to {}".format(name))
# ENDSECTION