diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | bot.py | 10 | ||||
-rw-r--r-- | commands/basic_games.py | 204 | ||||
-rw-r--r-- | commands/economy.py | 57 | ||||
-rw-r--r-- | commands/inventory.py | 101 | ||||
-rw-r--r-- | commands/rank.py | 51 | ||||
-rw-r--r-- | commands/shop.py | 88 | ||||
-rw-r--r-- | exp.py | 54 | ||||
-rw-r--r-- | initialise_db.py | 91 | ||||
-rw-r--r-- | mee6.py | 0 | ||||
-rw-r--r-- | models/inventory.py | 12 | ||||
-rw-r--r-- | models/item.py | 11 | ||||
-rw-r--r-- | models/level.py | 9 | ||||
-rw-r--r-- | models/models.py | 0 | ||||
-rw-r--r-- | models/user.py | 8 | ||||
-rw-r--r-- | shop.yaml.example | 13 |
16 files changed, 669 insertions, 43 deletions
@@ -1 +1,4 @@ config.yaml +shop.yaml +.vscode +__pycache__/ @@ -4,6 +4,7 @@ import datetime from discord_slash import SlashContext, SlashCommand from discord.ext.commands import Bot from models.user import User +from exp import Exp with open("config.yaml", "r") as yamlfile: @@ -18,6 +19,7 @@ intents.members = True bot = Bot(command_prefix="!", self_bot=True, intents=intents) slash = SlashCommand(bot, sync_commands=True) +bot_channel = None # Runs once bot has connected to discord @@ -32,14 +34,15 @@ async def on_ready(): for channel in guild.channels: if channel.name == config["discord_channel"]: print(f"{time_now}: Found channel {channel.name}!") + bot_channel = channel @bot.event async def on_message(message): print(message.author.id) user = User.get(User.discord_id == message.author.id) - user.add_message() - print(user.display_name) + exp = Exp(user, message.channel) + await exp.calculate_exp() @slash.slash( @@ -54,4 +57,7 @@ async def test(ctx: SlashContext): bot.load_extension("commands.economy") bot.load_extension("commands.basic_games") +bot.load_extension("commands.rank") +bot.load_extension("commands.shop") +bot.load_extension("commands.inventory") bot.run(config["discord_token"]) diff --git a/commands/basic_games.py b/commands/basic_games.py index 0b594ba..66524cd 100644 --- a/commands/basic_games.py +++ b/commands/basic_games.py @@ -1,5 +1,6 @@ from discord.ext.commands import Bot, Cog from discord_slash import cog_ext, SlashContext +from discord import Embed from discord_slash.utils.manage_commands import create_option, create_choice from base import config from models.user import User @@ -41,29 +42,206 @@ class BasicGames(Cog): async def coin_flip(self, ctx: SlashContext, num_coins: int, choice: int): user = User.get(User.discord_id == ctx.author_id) - await ctx.send(content=f"{user.username} is betting {num_coins} coins on {choice}") - result = random.randrange(0, 1) - choices = ["Heads", "Tails"] - await ctx.send(content=f"Coin flip lands on {choices[result]}") - if choice == choices[result]: - await ctx.send(content=f"You win {num_coins * 2} coins!") - user.add_coins(num_coins * 2) - else: - await ctx.send(content=f"You lose {num_coins} coins :(") + await ctx.send( + content=f"{user.username} is betting {num_coins} {config['currency']} on {choice}" + ) + result = random.randint(0, 200) + if result <= 110: + if choice == "Heads": + await ctx.send(content="Coin flip lands on Tails") + else: + await ctx.send(content="Coin flip lands on Heads") + + embed = Embed(description=f"{ctx.author.mention} loses!", colour=0xFF0000) + embed.add_field(name="Lost:", value=f"{num_coins} {config['currency']}") user.remove_coins(num_coins) + elif result > 110 and result < 199: + if choice == "Heads": + await ctx.send(content="Coin flip lands on Heads") + else: + await ctx.send(content="Coin flip lands on Tails") + embed = Embed(description=f"{ctx.author.mention} wins!", colour=0x00FF00) + embed.add_field(name="Prize:", value=f"{num_coins} {config['currency']}") + user.add_coins(num_coins) + elif result >= 199: + winnings = num_coins * 2 + embed = Embed( + description=f"The coin lands on it's side!{ctx.author.mention} wins double!", + colour=0x00FF00, + ) + embed.add_field(name="Prize:", value=f"{winnings} {config['currency']}") + user.add_coins(winnings) + await ctx.send(embed=embed) user.save() @cog_ext.cog_slash( name="dice", description="Roll some dice.", guild_ids=[config["discord_server_id"]], + options=[ + create_option( + name="num_coins", + description="coins to bet", + option_type=4, + required=True, + ), + ], + ) + async def dice(self, ctx: SlashContext, num_coins: int): + user = User.get(User.discord_id == ctx.author_id) + if user.currency < num_coins: + await ctx.send( + content=f"{user.display_name}, you don't have enough {config['currency']} for that bet" + ) + return False + + results = [ + random.randint(1, 6), + random.randint(1, 6), + random.randint(1, 6), + random.randint(1, 6), + ] + await ctx.send(content=f"{user.display_name}, you roll a {results[0]} and a {results[1]}") + + user_total = results[0] + results[1] + bot_total = results[2] + results[3] + if user_total == 12: + winnings = num_coins * 3 + + embed = Embed( + description=f"{ctx.author.mention} rolls a double 6!!! You win!", colour=0x00FF00 + ) + embed.add_field(name="Prize:", value=f"{winnings} {config['currency']}") + user.add_coins(winnings) + elif results[0] == results[1]: + winnings = num_coins * 2 + embed = Embed( + description=f"{ctx.author.mention} rolls a double!! You win!", colour=0x00FF00 + ) + embed.add_field(name="Prize:", value=f"{winnings} {config['currency']}") + user.add_coins(winnings) + else: + await ctx.channel.send( + content=f"{user.display_name}, I rolled a {results[2]} and a {results[3]}" + ) + if user_total > bot_total: + embed = Embed(description=f"{ctx.author.mention} wins!", colour=0x00FF00) + embed.add_field(name="Prize:", value=f"{num_coins} {config['currency']}") + user.add_coins(num_coins) + elif user_total == bot_total: + embed = Embed( + description=f"{ctx.author.mention}, it's a draw. Have your money back...", + colour=0xFFFF00, + ) + else: + embed = Embed( + description=f"{ctx.author.mention} loses the dice roll :(", + colour=0xFF0000, + ) + embed.add_field(name="Lost:", value=f"{num_coins} {config['currency']}") + user.remove_coins(num_coins) + await ctx.channel.send(embed=embed) + user.save() + + @cog_ext.cog_slash( + name="slots", + description="Pull the slot machine.", + guild_ids=[config["discord_server_id"]], ) - async def dice(self, ctx: SlashContext): - print("dice") + async def slots(self, ctx: SlashContext): user = User.get(User.discord_id == ctx.author_id) - result = random.randrange(1, 6) - await ctx.send(content=f"{user.display_name}, you roll a {result}") + cost = 10 + if user.currency < cost: + await ctx.send( + content=f"{user.display_name}, you don't have enough {config['currency']}, it costs 100 {config['currency']} to play" + ) + return False + + await ctx.send( + content=f"{user.display_name}, you put {cost} {config['currency']} in the machine and pull the handle..." + ) + user.remove_coins(cost) + + slots = config["slots"] + + e = [] + for slot in slots: + for i in range(slot["rarity"]): + e.append(slot) + total = len(e) - 1 + results = [ + e[random.randint(0, total)], + e[random.randint(0, total)], + e[random.randint(0, total)], + ] + results_top = [ + e[random.randint(0, total)], + e[random.randint(0, total)], + e[random.randint(0, total)], + ] + results_bottom = [ + e[random.randint(0, total)], + e[random.randint(0, total)], + e[random.randint(0, total)], + ] + + result_text = "" + # e = list(config["slots"].values()) + winnings = 0 + + for r in results_top: + result_text += r["dark"] + result_text += "\n" + + for r in results: + result_text += r["emoji"] + result_text += "\n" + + for r in results_bottom: + result_text += r["dark"] + result_text += "\n" + + double = False + triple = False + + if results[0]["name"] == results[1]["name"] and results[0]["name"] == results[2]["name"]: + triple = True + winnings += results[0]["reward_triple"] + elif results[0]["name"] == results[1]["name"] or results[0]["name"] == results[2]["name"]: + double = True + winnings += results[0]["reward_double"] + elif results[1]["name"] == results[2]["name"]: + double = True + winnings += results[1]["reward_double"] + else: + for r in results: + winnings += r["reward_single"] + + await ctx.channel.send(content=result_text) + + if winnings == 0: + embed = Embed(description=f"No match :( {ctx.author.mention} loses...", colour=0xFF0000) + embed.add_field(name="Lost:", value=f"{cost} {config['currency']}") + else: + if triple: + embed = Embed( + description=f"JACKPOT! {ctx.author.mention} wins with a triple!!!", + colour=0x00FF00, + ) + elif double: + embed = Embed( + description=f"Ding ding! {ctx.author.mention} wins with a double!!", + colour=0x00FF00, + ) + else: + embed = Embed(description=f"{ctx.author.mention} wins!", colour=0x00FF00) + + embed.add_field(name="Prize:", value=f"{winnings} {config['currency']}") + user.add_coins(winnings) + + await ctx.channel.send(embed=embed) + user.save() def setup(bot): diff --git a/commands/economy.py b/commands/economy.py index 1960827..720a00d 100644 --- a/commands/economy.py +++ b/commands/economy.py @@ -1,7 +1,9 @@ from discord.ext.commands import Bot, Cog from discord_slash import cog_ext, SlashContext +from discord import Embed from base import config from models.user import User +import datetime import random import yaml @@ -22,10 +24,30 @@ class Economy(Cog): ) async def daily(self, ctx: SlashContext): user = User.get(User.discord_id == ctx.author_id) - num_coins = random.randrange(50, 100) - user.add_coins(num_coins) - user.save() - await ctx.send(content="Here have some coins") + time_now = datetime.datetime.utcnow() + day_ago = time_now - datetime.timedelta(hours=24) + if user.daily_gained_time is None: + user.daily_gained_time = day_ago + remaining = user.daily_gained_time - day_ago + print( + f"now: {time_now}, day: {day_ago}, user: {user.exp_gained_time}, remaining: {remaining}" + ) + if user.daily_gained_time is None or user.daily_gained_time <= day_ago: + num_coins = 10 + user.level * 2 + user.daily_gained_time = time_now + user.add_coins(num_coins) + user.save() + embed = Embed( + description=f"Here you go {ctx.author.mention}, have your daily coins", + colour=0x00FF00, + ) + embed.add_field(name="Gained:", value=f"{num_coins} {config['currency']}") + else: + embed = Embed( + description=f"No {config['currency']} for you {user.display_name}, come back in {remaining.seconds // 3600} hours, {(remaining.seconds % 3600) // 60 } minutes.", + colour=0xFF8800, + ) + await ctx.send(embed=embed) @cog_ext.cog_slash( name="coins", @@ -34,7 +56,32 @@ class Economy(Cog): ) async def coins(self, ctx: SlashContext): user = User.get(User.discord_id == ctx.author_id) - await ctx.send(content=f"{user.display_name}, you have {user.currency} coins") + embed = Embed( + description=f"{ctx.author.mention}, here is your current balance:", + colour=0x0000FF, + ) + embed.add_field(name="Currency:", value=f"{user.currency} {config['currency']}") + await ctx.send(embed=embed) + + @cog_ext.cog_slash( + name="leaderboard", + description="Show the currency leaderboard", + guild_ids=[config["discord_server_id"]], + ) + async def leaderboard(self, ctx: SlashContext): + users = User.select().order_by(User.currency.desc()).limit(10) + embed = Embed( + title="Currency Leaderboard", + colour=0x0000FF, + ) + i = 1 + for user in users: + embed.add_field( + name=f"#{i} {user.display_name}", value=f"{user.currency} {config['currency']}" + ) + i += 1 + + await ctx.send(embed=embed) def setup(bot): diff --git a/commands/inventory.py b/commands/inventory.py new file mode 100644 index 0000000..1f81d71 --- /dev/null +++ b/commands/inventory.py @@ -0,0 +1,101 @@ +from discord.ext.commands import Bot, Cog +from discord_slash import cog_ext, SlashContext +from discord_slash.utils.manage_commands import create_option, create_choice +from base import config +from models.user import User +from models.level import Level +from models.item import Item +from models.inventory import Inventory +from peewee import DoesNotExist +import random +import yaml + + +class InventoryCmd(Cog): + def __init__(self, bot: Bot): + self.bot = bot + with open("config.yaml", "r") as yamlfile: + config = yaml.load(yamlfile, Loader=yaml.CLoader) + print("Read config successful") + self.config = config + print(config["discord_server_id"]) + + @cog_ext.cog_slash( + name="inventory", + description="See your inventory", + guild_ids=[config["discord_server_id"]], + ) + async def inventory(self, ctx: SlashContext): + user = User.get(User.discord_id == ctx.author_id) + inventory = Inventory.select().join(Item).limit(100).where(Inventory.user == user.id) + print(inventory) + shop_text = "" + for inventory_item in inventory: + shop_text += ( + f"#{inventory_item.item.id}: {inventory_item.item.name} x{inventory_item.stock} \n" + ) + await ctx.send(content=shop_text) + + @cog_ext.cog_slash( + name="use", + description="Use an item", + guild_ids=[config["discord_server_id"]], + options=[ + create_option( + name="item", + description="Item to use", + option_type=3, + required=True, + ), + create_option( + name="target", + description="User to use the item on", + option_type=6, + required=False, + ), + ], + ) + async def use(self, ctx: SlashContext, item: str, target=None): + user = User.get(User.discord_id == ctx.author_id) + + try: + if is_number(item): + using_item = Item.get(Item.id == item) + else: + using_item = Item.get(Item.name == item) + except DoesNotExist: + await ctx.send(content=f"Item {item} not found. Try using the item number") + + try: + print(f"user: {user}, item: {using_item}") + inventory_item = Inventory.get(user=user, item=using_item) + except DoesNotExist: + await ctx.send(content=f"You don't own any {item}!") + if inventory_item.stock > 0: + inventory_item.stock -= 1 + inventory_item.save() + use_text = using_item.text + use_text = use_text.replace("{u}", ctx.author.mention) + if target is not None: + use_text = use_text.replace("{t}", target.mention) + message = await ctx.send(content=f"Solarus used *{using_item.name}*!") + await ctx.send(content=f"*{use_text}*") + if using_item.reward_rank is not None: + print(using_item.reward_rank) + role = ctx.author.guild.get_role(int(using_item.reward_rank)) + await ctx.author.add_roles(role) + else: + await ctx.send(content=f"You don't own any more {using_item.name}!") + + +def is_number(s): + try: + int(s) + return True + except ValueError: + return False + + +def setup(bot): + bot.add_cog(InventoryCmd(bot)) + print("Loaded Inventory") diff --git a/commands/rank.py b/commands/rank.py new file mode 100644 index 0000000..a16b1c2 --- /dev/null +++ b/commands/rank.py @@ -0,0 +1,51 @@ +from discord.ext.commands import Bot, Cog +from discord_slash import cog_ext, SlashContext +from base import config +from models.user import User +from models.level import Level +import random +import yaml + + +class Rank(Cog): + def __init__(self, bot: Bot): + self.bot = bot + with open("config.yaml", "r") as yamlfile: + config = yaml.load(yamlfile, Loader=yaml.CLoader) + print("Read config successful") + self.config = config + print(config["discord_server_id"]) + + @cog_ext.cog_slash( + name="rank", + description="Show your rank.", + guild_ids=[config["discord_server_id"]], + ) + async def rank(self, ctx: SlashContext): + user = User.get(User.discord_id == ctx.author_id) + next_level = Level.get(Level.level == user.level + 1) + + await ctx.send( + content=f"Hey {user.display_name}, you are level {user.level}. You're at {user.exp}/{next_level.exp_required}" + ) + + @cog_ext.cog_slash( + name="ranks", + description="Show the rank leaderboard", + guild_ids=[config["discord_server_id"]], + ) + async def ranks(self, ctx: SlashContext): + users = User.select().order_by(User.exp.desc()).limit(10) + rank_text = "" + for user in users: + next_level = Level.get(user.level + 1) + rank_text += ( + f"{user.display_name}: Level {user.level}, {user.exp}/{next_level.exp_required} \n" + ) + + await ctx.send(content=rank_text) + + +def setup(bot): + bot.add_cog(Rank(bot)) + print("Loaded Rank") diff --git a/commands/shop.py b/commands/shop.py new file mode 100644 index 0000000..5c9bb9f --- /dev/null +++ b/commands/shop.py @@ -0,0 +1,88 @@ +from discord.ext.commands import Bot, Cog +from discord_slash import cog_ext, SlashContext +from discord_slash.utils.manage_commands import create_option, create_choice +from base import config +from models.user import User +from models.level import Level +from models.item import Item +from models.inventory import Inventory +from peewee import DoesNotExist +import random +import yaml + + +class Shop(Cog): + def __init__(self, bot: Bot): + self.bot = bot + with open("config.yaml", "r") as yamlfile: + config = yaml.load(yamlfile, Loader=yaml.CLoader) + print("Read config successful") + self.config = config + print(config["discord_server_id"]) + + @cog_ext.cog_slash( + name="shop", + description="Browse the shop.", + guild_ids=[config["discord_server_id"]], + ) + async def shop(self, ctx: SlashContext): + items = Item.select().limit(100) + shop_text = "" + for item in items: + shop_text += f"#{item.id} {item.name}: {item.price} {config['currency']} \n" + await ctx.send(content=shop_text) + + @cog_ext.cog_slash( + name="buy", + description="Buy from the shop", + guild_ids=[config["discord_server_id"]], + options=[ + create_option( + name="item", + description="Item to buy", + option_type=3, + required=True, + ), + ], + ) + async def buy(self, ctx: SlashContext, item: str): + user = User.get(User.discord_id == ctx.author_id) + + try: + if is_number(item): + buying_item = Item.get(Item.id == item) + else: + buying_item = Item.get(Item.name == item) + except DoesNotExist: + await ctx.send(content=f"Item {item} not found. Try using the item number") + + else: + if user.currency >= buying_item.price: + try: + inventory = Inventory.get(user=user, item=buying_item) + except DoesNotExist: + inventory = Inventory(user=user, item=buying_item, stock=0) + inventory.stock += 1 + user.currency -= buying_item.price + inventory.save() + user.save() + await ctx.send( + content=f"{user.display_name} bought the item: {buying_item.name} for {buying_item.price} {config['currency']}" + ) + else: + await ctx.send( + content=f"{buying_item.name} costs {buying_item.price} {config['currency']}. You can't afford that {user.display_name}!" + ) + + +def is_number(s): + try: + int(s) + return True + except ValueError: + return False + + +def setup(bot): + bot.add_cog(Shop(bot)) + print("Loaded Shop") @@ -0,0 +1,54 @@ +import datetime +import random +from base import config +from models.level import Level +from models.user import User +from discord import TextChannel + + +class Exp: + def __init__(self, user: User, bot_channel: TextChannel): + self.user = user + self.channel = bot_channel + + async def calculate_exp(self): + self.add_message(self.user) + gained_exp = self.gain_exp(self.user) + if gained_exp: + if self.check_level_up(self.user): + await self.level_up(self.user, self.channel) + + def add_message(self, user: User): + messages = user.message_count + user.message_count = messages + 1 + user.save() + + def gain_exp(self, user: User): + time_now = datetime.datetime.utcnow() + minute_ago = time_now - datetime.timedelta(seconds=60) + print(f"now: {time_now}, minute: {minute_ago}, user: {user.exp_gained_time}") + if user.exp_gained_time is None or user.exp_gained_time < minute_ago: + gained_exp = random.randrange(15, 25) + total_exp = user.exp + gained_exp + user.exp = total_exp + user.exp_gained_time = time_now + user.save() + return True + else: + return False + + def check_level_up(self, user: User): + next_level = Level.get(user.level + 1) + if user.exp > next_level.exp_required: + return True + else: + return False + + async def level_up(self, user: User, channel: TextChannel): + user.level += 1 + level = Level.get(level=user.level) + user.currency += level.reward_currency + await channel.send( + f"Congrats {user.display_name}, you levelled up to {user.level}! You win {level.reward_currency} {config['currency']}!" + ) + user.save() diff --git a/initialise_db.py b/initialise_db.py index 62e6316..fc89ad9 100644 --- a/initialise_db.py +++ b/initialise_db.py @@ -1,35 +1,64 @@ from models.user import User +from models.level import Level +from models.item import Item +from models.inventory import Inventory from mee6_py_api import API -from base import db, config, client +from base import db import datetime +import discord +import yaml +import logging + +logger = logging.getLogger("peewee") +logger.addHandler(logging.StreamHandler()) +logger.setLevel(logging.DEBUG) + +with open("config.yaml", "r") as yamlfile: + config = yaml.load(yamlfile, Loader=yaml.CLoader) + print("Read config successful") + config = config + +client = discord.Client() # Runs once bot has connected to discord @client.event async def on_ready(): - db.create_tables([User]) + db.create_tables([User, Level, Item, Inventory]) time_now = datetime.datetime.utcnow() print(f"{time_now}: {client.user} has connected to Discord!") - users = [] for guild in client.guilds: if guild.id == config["discord_server_id"]: print(f"{time_now}: {client.user} has joined {guild.name}!") - for member in guild.members: - print(member) - print(member.display_name) - print(member.nick) - print(member.joined_at) - users.append( - User( - username=member.name, - display_name=member.display_name, - discord_id=member.id, - joined_date=member.joined_at, - ) - ) + # populate_users(guild.members) + # cur_exp = 0 + # for i in range(10): + # print(f"level {i}: {cur_exp} exp") + # level = Level(level=i, exp_required=cur_exp) + # level.save() + # print(f"{cur_exp} + 5 * {(pow(i,2))} + {(50 * i)} + 100") + # cur_exp = cur_exp + 5 * pow(i, 2) + (50 * i) + 100 + populate_levels() + # populate_items() + + +def populate_users(users: list): + for member in guild.members: + print(member) + print(member.display_name) + print(member.nick) + print(member.joined_at) + users.append( + User( + username=member.name, + display_name=member.display_name, + discord_id=member.id, + joined_date=member.joined_at, + ) + ) mee6API = API(config["discord_server_id"]) - mee6_levels = await mee6API.levels.get_leaderboard_page(0) + mee6_levels = mee6API.levels.get_leaderboard_page(0) for user in users: for mee6_user in mee6_levels["players"]: if mee6_user["username"] == user.username: @@ -40,4 +69,32 @@ async def on_ready(): user.save() +def populate_levels(): + cur_exp = 0 + for i in range(100): + reward_currency = i * 10 + if i % 10 == 0: + reward_currency *= 1.5 + print(f"level {i}: {cur_exp} exp, {reward_currency} coins") + level = Level(level=i, exp_required=cur_exp, reward_currency=reward_currency) + level.save() + print(f"{cur_exp} + 5 * {(pow(i,2))} + {(50 * i)} + 100") + cur_exp = cur_exp + 5 * pow(i, 2) + (50 * i) + 100 + + +def populate_items(): + with open("shop.yaml", "r") as yamlfile: + shop = yaml.load(yamlfile, Loader=yaml.CLoader) + print("Read shop successful") + for name, shop_item in shop["items"].items(): + print(f"{name}: {shop_item}") + if "rank" in shop_item.keys(): + item = Item( + name=name, price=shop_item["price"], text=shop_item["text"], rank=shop_item["rank"] + ) + else: + item = Item(name=name, price=shop_item["price"], text=shop_item["text"]) + item.save() + + client.run(config["discord_token"]) diff --git a/models/inventory.py b/models/inventory.py new file mode 100644 index 0000000..90f4cba --- /dev/null +++ b/models/inventory.py @@ -0,0 +1,12 @@ +from peewee import IntegerField, ForeignKeyField + +from base import BaseModel +from models.user import User +from models.item import Item + + +class Inventory(BaseModel): + + user = ForeignKeyField(User) + item = ForeignKeyField(Item) + stock = IntegerField(default=0) diff --git a/models/item.py b/models/item.py new file mode 100644 index 0000000..194b69c --- /dev/null +++ b/models/item.py @@ -0,0 +1,11 @@ +from peewee import TextField, IntegerField + +from base import BaseModel + + +class Item(BaseModel): + + name = TextField() + price = IntegerField() + text = TextField() + reward_rank = TextField(null=True) diff --git a/models/level.py b/models/level.py new file mode 100644 index 0000000..2dc61d9 --- /dev/null +++ b/models/level.py @@ -0,0 +1,9 @@ +from peewee import IntegerField, BigIntegerField + +from base import BaseModel + + +class Level(BaseModel): + level = IntegerField(primary_key=True) + exp_required = BigIntegerField() + reward_currency = IntegerField(null=True) diff --git a/models/models.py b/models/models.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/models/models.py diff --git a/models/user.py b/models/user.py index dcf35ab..c38135d 100644 --- a/models/user.py +++ b/models/user.py @@ -1,6 +1,5 @@ from peewee import TextField, IntegerField, DateTimeField import datetime -import random from base import BaseModel @@ -15,14 +14,11 @@ class User(BaseModel): currency = IntegerField() message_count = IntegerField() joined_date = DateTimeField(default=datetime.datetime.now) + exp_gained_time = DateTimeField(default=datetime.datetime.now) + daily_gained_time = DateTimeField(default=datetime.datetime.now) def add_coins(self, additional_coins: int): self.currency = self.currency + additional_coins def remove_coins(self, lost_coins: int): self.currency = self.currency - lost_coins - - def add_message(self): - self.message_count += 1 - gained_exp = random.randrange(10, 15) - self.exp += gained_exp diff --git a/shop.yaml.example b/shop.yaml.example new file mode 100644 index 0000000..7b7e078 --- /dev/null +++ b/shop.yaml.example @@ -0,0 +1,13 @@ +items: + Banana: + price: 10 + description: "Long and yellow" + text: "Have a banana!" + Trout: + price: 20 + description: "A bit fishy" + text: "{u} slaps {t} around a bit with a large trout." + Gold Star: + price: 100 + text: "You pin the gold star on your shirt. Aren't you special?" + rank: "Gold Star"
\ No newline at end of file |