mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-09 04:38:55 -05:00
[Economy] Leaderboard pagify (#475)
* Some PEP8 stuff * pagify leaderboard
This commit is contained in:
parent
d349a0cab7
commit
8a7be3b812
217
cogs/economy.py
217
cogs/economy.py
@ -6,12 +6,15 @@ from datetime import datetime
|
|||||||
from random import randint
|
from random import randint
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from .utils import checks
|
from .utils import checks
|
||||||
|
from cogs.utils.chat_formatting import pagify, box
|
||||||
from __main__ import send_cmd_help
|
from __main__ import send_cmd_help
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
default_settings = {"PAYDAY_TIME" : 300, "PAYDAY_CREDITS" : 120, "SLOT_MIN" : 5, "SLOT_MAX" : 100, "SLOT_TIME" : 0, "REGISTER_CREDITS" : 0}
|
default_settings = {"PAYDAY_TIME": 300, "PAYDAY_CREDITS": 120,
|
||||||
|
"SLOT_MIN": 5, "SLOT_MAX": 100, "SLOT_TIME": 0,
|
||||||
|
"REGISTER_CREDITS": 0}
|
||||||
|
|
||||||
slot_payouts = """Slot machine payouts:
|
slot_payouts = """Slot machine payouts:
|
||||||
:two: :two: :six: Bet * 5000
|
:two: :two: :six: Bet * 5000
|
||||||
@ -49,6 +52,7 @@ class SameSenderAndReceiver(BankError):
|
|||||||
|
|
||||||
|
|
||||||
class Bank:
|
class Bank:
|
||||||
|
|
||||||
def __init__(self, bot, file_path):
|
def __init__(self, bot, file_path):
|
||||||
self.accounts = dataIO.load_json(file_path)
|
self.accounts = dataIO.load_json(file_path)
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
@ -58,15 +62,15 @@ class Bank:
|
|||||||
if not self.account_exists(user):
|
if not self.account_exists(user):
|
||||||
if server.id not in self.accounts:
|
if server.id not in self.accounts:
|
||||||
self.accounts[server.id] = {}
|
self.accounts[server.id] = {}
|
||||||
if user.id in self.accounts: # Legacy account
|
if user.id in self.accounts: # Legacy account
|
||||||
balance = self.accounts[user.id]["balance"]
|
balance = self.accounts[user.id]["balance"]
|
||||||
else:
|
else:
|
||||||
balance = initial_balance
|
balance = initial_balance
|
||||||
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
account = {"name" : user.name,
|
account = {"name": user.name,
|
||||||
"balance" : balance,
|
"balance": balance,
|
||||||
"created_at" : timestamp
|
"created_at": timestamp
|
||||||
}
|
}
|
||||||
self.accounts[server.id][user.id] = account
|
self.accounts[server.id][user.id] = account
|
||||||
self._save_bank()
|
self._save_bank()
|
||||||
return self.get_account(user)
|
return self.get_account(user)
|
||||||
@ -154,8 +158,10 @@ class Bank:
|
|||||||
accounts = []
|
accounts = []
|
||||||
for server_id, v in self.accounts.items():
|
for server_id, v in self.accounts.items():
|
||||||
server = self.bot.get_server(server_id)
|
server = self.bot.get_server(server_id)
|
||||||
if server is None:# Servers that have since been left will be ignored
|
if server is None:
|
||||||
continue # Same for users_id from the old bank format
|
# Servers that have since been left will be ignored
|
||||||
|
# Same for users_id from the old bank format
|
||||||
|
continue
|
||||||
raw_server_accounts = deepcopy(self.accounts[server.id])
|
raw_server_accounts = deepcopy(self.accounts[server.id])
|
||||||
for k, v in raw_server_accounts.items():
|
for k, v in raw_server_accounts.items():
|
||||||
v["id"] = k
|
v["id"] = k
|
||||||
@ -192,6 +198,7 @@ class Bank:
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
raise NoAccount()
|
raise NoAccount()
|
||||||
|
|
||||||
|
|
||||||
class Economy:
|
class Economy:
|
||||||
"""Economy
|
"""Economy
|
||||||
|
|
||||||
@ -203,7 +210,7 @@ class Economy:
|
|||||||
self.bank = Bank(bot, "data/economy/bank.json")
|
self.bank = Bank(bot, "data/economy/bank.json")
|
||||||
self.file_path = "data/economy/settings.json"
|
self.file_path = "data/economy/settings.json"
|
||||||
self.settings = dataIO.load_json(self.file_path)
|
self.settings = dataIO.load_json(self.file_path)
|
||||||
if "PAYDAY_TIME" in self.settings: #old format
|
if "PAYDAY_TIME" in self.settings: # old format
|
||||||
default_settings = self.settings
|
default_settings = self.settings
|
||||||
self.settings = {}
|
self.settings = {}
|
||||||
self.settings = defaultdict(lambda: default_settings, self.settings)
|
self.settings = defaultdict(lambda: default_settings, self.settings)
|
||||||
@ -224,39 +231,51 @@ class Economy:
|
|||||||
if ctx.message.server.id in self.settings:
|
if ctx.message.server.id in self.settings:
|
||||||
credits = self.settings[ctx.message.server.id].get("REGISTER_CREDITS", 0)
|
credits = self.settings[ctx.message.server.id].get("REGISTER_CREDITS", 0)
|
||||||
try:
|
try:
|
||||||
|
<<<<<<< HEAD
|
||||||
account = self.bank.create_account(user, initial_balance=credits)
|
account = self.bank.create_account(user, initial_balance=credits)
|
||||||
await self.bot.say("{} Account opened. Current balance: {}".format(user.mention,
|
await self.bot.say("{} Account opened. Current balance: {}".format(user.mention,
|
||||||
account.balance))
|
account.balance))
|
||||||
|
=======
|
||||||
|
account = self.bank.create_account(user)
|
||||||
|
await self.bot.say("{} Account opened. Current balance: {}".format(
|
||||||
|
user.mention, account.balance))
|
||||||
|
>>>>>>> cb472f9... Some PEP8 stuff
|
||||||
except AccountAlreadyExists:
|
except AccountAlreadyExists:
|
||||||
await self.bot.say("{} You already have an account at the Twentysix bank.".format(user.mention))
|
await self.bot.say("{} You already have an account at the"
|
||||||
|
" Twentysix bank.".format(user.mention))
|
||||||
|
|
||||||
@_bank.command(pass_context=True)
|
@_bank.command(pass_context=True)
|
||||||
async def balance(self, ctx, user : discord.Member=None):
|
async def balance(self, ctx, user: discord.Member=None):
|
||||||
"""Shows balance of user.
|
"""Shows balance of user.
|
||||||
|
|
||||||
Defaults to yours."""
|
Defaults to yours."""
|
||||||
if not user:
|
if not user:
|
||||||
user = ctx.message.author
|
user = ctx.message.author
|
||||||
try:
|
try:
|
||||||
await self.bot.say("{} Your balance is: {}".format(user.mention, self.bank.get_balance(user)))
|
await self.bot.say("{} Your balance is: {}".format(
|
||||||
|
user.mention, self.bank.get_balance(user)))
|
||||||
except NoAccount:
|
except NoAccount:
|
||||||
await self.bot.say("{} You don't have an account at the Twentysix bank."
|
await self.bot.say("{} You don't have an account at the"
|
||||||
" Type `{}bank register` to open one.".format(user.mention, ctx.prefix))
|
" Twentysix bank. Type `{}bank register`"
|
||||||
|
" to open one.".format(user.mention,
|
||||||
|
ctx.prefix))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
await self.bot.say("{}'s balance is {}".format(user.name, self.bank.get_balance(user)))
|
await self.bot.say("{}'s balance is {}".format(
|
||||||
|
user.name, self.bank.get_balance(user)))
|
||||||
except NoAccount:
|
except NoAccount:
|
||||||
await self.bot.say("That user has no bank account.")
|
await self.bot.say("That user has no bank account.")
|
||||||
|
|
||||||
@_bank.command(pass_context=True)
|
@_bank.command(pass_context=True)
|
||||||
async def transfer(self, ctx, user : discord.Member, sum : int):
|
async def transfer(self, ctx, user: discord.Member, sum: int):
|
||||||
"""Transfer credits to other users"""
|
"""Transfer credits to other users"""
|
||||||
author = ctx.message.author
|
author = ctx.message.author
|
||||||
try:
|
try:
|
||||||
self.bank.transfer_credits(author, user, sum)
|
self.bank.transfer_credits(author, user, sum)
|
||||||
logger.info("{}({}) transferred {} credits to {}({})".format(
|
logger.info("{}({}) transferred {} credits to {}({})".format(
|
||||||
author.name, author.id, sum, user.name, user.id))
|
author.name, author.id, sum, user.name, user.id))
|
||||||
await self.bot.say("{} credits have been transferred to {}'s account.".format(sum, user.name))
|
await self.bot.say("{} credits have been transferred to {}'s"
|
||||||
|
" account.".format(sum, user.name))
|
||||||
except NegativeValue:
|
except NegativeValue:
|
||||||
await self.bot.say("You need to transfer at least 1 credit.")
|
await self.bot.say("You need to transfer at least 1 credit.")
|
||||||
except SameSenderAndReceiver:
|
except SameSenderAndReceiver:
|
||||||
@ -268,39 +287,58 @@ class Economy:
|
|||||||
|
|
||||||
@_bank.command(name="set", pass_context=True)
|
@_bank.command(name="set", pass_context=True)
|
||||||
@checks.admin_or_permissions(manage_server=True)
|
@checks.admin_or_permissions(manage_server=True)
|
||||||
async def _set(self, ctx, user : discord.Member, sum : int):
|
async def _set(self, ctx, user: discord.Member, sum: int):
|
||||||
"""Sets credits of user's bank account
|
"""Sets credits of user's bank account
|
||||||
|
|
||||||
Admin/owner restricted."""
|
Admin/owner restricted."""
|
||||||
author = ctx.message.author
|
author = ctx.message.author
|
||||||
try:
|
try:
|
||||||
self.bank.set_credits(user, sum)
|
self.bank.set_credits(user, sum)
|
||||||
logger.info("{}({}) set {} credits to {} ({})".format(author.name, author.id, str(sum), user.name, user.id))
|
logger.info("{}({}) set {} credits to {} ({})".format(
|
||||||
await self.bot.say("{}'s credits have been set to {}".format(user.name, str(sum)))
|
author.name, author.id, str(sum), user.name, user.id))
|
||||||
|
await self.bot.say("{}'s credits have been set to {}".format(
|
||||||
|
user.name, str(sum)))
|
||||||
except NoAccount:
|
except NoAccount:
|
||||||
await self.bot.say("User has no bank account.")
|
await self.bot.say("User has no bank account.")
|
||||||
|
|
||||||
@commands.command(pass_context=True, no_pm=True)
|
@commands.command(pass_context=True, no_pm=True)
|
||||||
async def payday(self, ctx): # TODO
|
async def payday(self, ctx): # TODO
|
||||||
"""Get some free credits"""
|
"""Get some free credits"""
|
||||||
author = ctx.message.author
|
author = ctx.message.author
|
||||||
server = author.server
|
server = author.server
|
||||||
id = author.id
|
id = author.id
|
||||||
if self.bank.account_exists(author):
|
if self.bank.account_exists(author):
|
||||||
if id in self.payday_register[server.id]:
|
if id in self.payday_register[server.id]:
|
||||||
seconds = abs(self.payday_register[server.id][id] - int(time.perf_counter()))
|
seconds = abs(self.payday_register[server.id][
|
||||||
if seconds >= self.settings[server.id]["PAYDAY_TIME"]:
|
id] - int(time.perf_counter()))
|
||||||
self.bank.deposit_credits(author, self.settings[server.id]["PAYDAY_CREDITS"])
|
if seconds >= self.settings[server.id]["PAYDAY_TIME"]:
|
||||||
self.payday_register[server.id][id] = int(time.perf_counter())
|
self.bank.deposit_credits(author, self.settings[
|
||||||
await self.bot.say("{} Here, take some credits. Enjoy! (+{} credits!)".format(author.mention, str(self.settings[server.id]["PAYDAY_CREDITS"])))
|
server.id]["PAYDAY_CREDITS"])
|
||||||
|
self.payday_register[server.id][
|
||||||
|
id] = int(time.perf_counter())
|
||||||
|
await self.bot.say(
|
||||||
|
"{} Here, take some credits. Enjoy! (+{}"
|
||||||
|
" credits!)".format(
|
||||||
|
author.mention,
|
||||||
|
str(self.settings[server.id]["PAYDAY_CREDITS"])))
|
||||||
else:
|
else:
|
||||||
await self.bot.say("{} Too soon. For your next payday you have to wait {}.".format(author.mention, self.display_time(self.settings[server.id]["PAYDAY_TIME"] - seconds)))
|
dtime = self.display_time(
|
||||||
|
self.settings[server.id]["PAYDAY_TIME"] - seconds)
|
||||||
|
await self.bot.say(
|
||||||
|
"{} Too soon. For your next payday you have to"
|
||||||
|
" wait {}.".format(author.mention, dtime))
|
||||||
else:
|
else:
|
||||||
self.payday_register[server.id][id] = int(time.perf_counter())
|
self.payday_register[server.id][id] = int(time.perf_counter())
|
||||||
self.bank.deposit_credits(author, self.settings[server.id]["PAYDAY_CREDITS"])
|
self.bank.deposit_credits(author, self.settings[
|
||||||
await self.bot.say("{} Here, take some credits. Enjoy! (+{} credits!)".format(author.mention, str(self.settings[server.id]["PAYDAY_CREDITS"])))
|
server.id]["PAYDAY_CREDITS"])
|
||||||
|
await self.bot.say(
|
||||||
|
"{} Here, take some credits. Enjoy! (+{} credits!)".format(
|
||||||
|
author.mention,
|
||||||
|
str(self.settings[server.id]["PAYDAY_CREDITS"])))
|
||||||
else:
|
else:
|
||||||
await self.bot.say("{} You need an account to receive credits. Type `{}bank register` to open one.".format(author.mention, ctx.prefix))
|
await self.bot.say("{} You need an account to receive credits."
|
||||||
|
" Type `{}bank register` to open one.".format(
|
||||||
|
author.mention, ctx.prefix))
|
||||||
|
|
||||||
@commands.group(pass_context=True)
|
@commands.group(pass_context=True)
|
||||||
async def leaderboard(self, ctx):
|
async def leaderboard(self, ctx):
|
||||||
@ -311,42 +349,41 @@ class Economy:
|
|||||||
await ctx.invoke(self._server_leaderboard)
|
await ctx.invoke(self._server_leaderboard)
|
||||||
|
|
||||||
@leaderboard.command(name="server", pass_context=True)
|
@leaderboard.command(name="server", pass_context=True)
|
||||||
async def _server_leaderboard(self, ctx, top : int=10):
|
async def _server_leaderboard(self, ctx, top: int=10):
|
||||||
"""Prints out the server's leaderboard
|
"""Prints out the server's leaderboard
|
||||||
|
|
||||||
Defaults to top 10""" #Originally coded by Airenkun - edited by irdumb
|
Defaults to top 10"""
|
||||||
|
# Originally coded by Airenkun - edited by irdumb
|
||||||
server = ctx.message.server
|
server = ctx.message.server
|
||||||
if top < 1:
|
if top < 1:
|
||||||
top = 10
|
top = 10
|
||||||
bank_sorted = sorted(self.bank.get_server_accounts(server),
|
bank_sorted = sorted(self.bank.get_server_accounts(server),
|
||||||
key=lambda x: x.balance, reverse=True)
|
key=lambda x: x.balance, reverse=True)
|
||||||
if len(bank_sorted) < top:
|
if len(bank_sorted) < top:
|
||||||
top = len(bank_sorted)
|
top = len(bank_sorted)
|
||||||
topten = bank_sorted[:top]
|
topten = bank_sorted[:top]
|
||||||
highscore = ""
|
highscore = ""
|
||||||
place = 1
|
place = 1
|
||||||
for acc in topten:
|
for acc in topten:
|
||||||
highscore += str(place).ljust(len(str(top))+1)
|
highscore += str(place).ljust(len(str(top)) + 1)
|
||||||
highscore += (acc.name+" ").ljust(23-len(str(acc.balance)))
|
highscore += (acc.name + " ").ljust(23 - len(str(acc.balance)))
|
||||||
highscore += str(acc.balance) + "\n"
|
highscore += str(acc.balance) + "\n"
|
||||||
place += 1
|
place += 1
|
||||||
if highscore:
|
if highscore != "":
|
||||||
if len(highscore) < 1985:
|
for page in pagify(highscore, shorten_by=12):
|
||||||
await self.bot.say("```py\n"+highscore+"```")
|
await self.bot.say(box(page, lang="py"))
|
||||||
else:
|
|
||||||
await self.bot.say("The leaderboard is too big to be displayed. Try with a lower <top> parameter.")
|
|
||||||
else:
|
else:
|
||||||
await self.bot.say("There are no accounts in the bank.")
|
await self.bot.say("There are no accounts in the bank.")
|
||||||
|
|
||||||
@leaderboard.command(name="global")
|
@leaderboard.command(name="global")
|
||||||
async def _global_leaderboard(self, top : int=10):
|
async def _global_leaderboard(self, top: int=10):
|
||||||
"""Prints out the global leaderboard
|
"""Prints out the global leaderboard
|
||||||
|
|
||||||
Defaults to top 10"""
|
Defaults to top 10"""
|
||||||
if top < 1:
|
if top < 1:
|
||||||
top = 10
|
top = 10
|
||||||
bank_sorted = sorted(self.bank.get_all_accounts(),
|
bank_sorted = sorted(self.bank.get_all_accounts(),
|
||||||
key=lambda x: x.balance, reverse=True)
|
key=lambda x: x.balance, reverse=True)
|
||||||
unique_accounts = []
|
unique_accounts = []
|
||||||
for acc in bank_sorted:
|
for acc in bank_sorted:
|
||||||
if not self.already_in_list(unique_accounts, acc):
|
if not self.already_in_list(unique_accounts, acc):
|
||||||
@ -357,15 +394,14 @@ class Economy:
|
|||||||
highscore = ""
|
highscore = ""
|
||||||
place = 1
|
place = 1
|
||||||
for acc in topten:
|
for acc in topten:
|
||||||
highscore += str(place).ljust(len(str(top))+1)
|
highscore += str(place).ljust(len(str(top)) + 1)
|
||||||
highscore += ("{} |{}| ".format(acc.name, acc.server.name)).ljust(23-len(str(acc.balance)))
|
highscore += ("{} |{}| ".format(acc.name, acc.server.name)
|
||||||
|
).ljust(23 - len(str(acc.balance)))
|
||||||
highscore += str(acc.balance) + "\n"
|
highscore += str(acc.balance) + "\n"
|
||||||
place += 1
|
place += 1
|
||||||
if highscore:
|
if highscore != "":
|
||||||
if len(highscore) < 1985:
|
for page in pagify(highscore, shorten_by=12):
|
||||||
await self.bot.say("```py\n"+highscore+"```")
|
await self.bot.say(box(page, lang="py"))
|
||||||
else:
|
|
||||||
await self.bot.say("The leaderboard is too big to be displayed. Try with a lower <top> parameter.")
|
|
||||||
else:
|
else:
|
||||||
await self.bot.say("There are no accounts in the bank.")
|
await self.bot.say("There are no accounts in the bank.")
|
||||||
|
|
||||||
@ -381,7 +417,7 @@ class Economy:
|
|||||||
await self.bot.whisper(slot_payouts)
|
await self.bot.whisper(slot_payouts)
|
||||||
|
|
||||||
@commands.command(pass_context=True, no_pm=True)
|
@commands.command(pass_context=True, no_pm=True)
|
||||||
async def slot(self, ctx, bid : int):
|
async def slot(self, ctx, bid: int):
|
||||||
"""Play the slot machine"""
|
"""Play the slot machine"""
|
||||||
author = ctx.message.author
|
author = ctx.message.author
|
||||||
server = author.server
|
server = author.server
|
||||||
@ -391,8 +427,9 @@ class Economy:
|
|||||||
if self.bank.can_spend(author, bid):
|
if self.bank.can_spend(author, bid):
|
||||||
if bid >= self.settings[server.id]["SLOT_MIN"] and bid <= self.settings[server.id]["SLOT_MAX"]:
|
if bid >= self.settings[server.id]["SLOT_MIN"] and bid <= self.settings[server.id]["SLOT_MAX"]:
|
||||||
if author.id in self.slot_register:
|
if author.id in self.slot_register:
|
||||||
if abs(self.slot_register[author.id] - int(time.perf_counter())) >= self.settings[server.id]["SLOT_TIME"]:
|
if abs(self.slot_register[author.id] - int(time.perf_counter())) >= self.settings[server.id]["SLOT_TIME"]:
|
||||||
self.slot_register[author.id] = int(time.perf_counter())
|
self.slot_register[author.id] = int(
|
||||||
|
time.perf_counter())
|
||||||
await self.slot_machine(ctx.message, bid)
|
await self.slot_machine(ctx.message, bid)
|
||||||
else:
|
else:
|
||||||
await self.bot.say("Slot machine is still cooling off! Wait {} seconds between each pull".format(self.settings[server.id]["SLOT_TIME"]))
|
await self.bot.say("Slot machine is still cooling off! Wait {} seconds between each pull".format(self.settings[server.id]["SLOT_TIME"]))
|
||||||
@ -405,49 +442,66 @@ class Economy:
|
|||||||
await self.bot.say("{0} You need an account with enough funds to play the slot machine.".format(author.mention))
|
await self.bot.say("{0} You need an account with enough funds to play the slot machine.".format(author.mention))
|
||||||
|
|
||||||
async def slot_machine(self, message, bid):
|
async def slot_machine(self, message, bid):
|
||||||
reel_pattern = [":cherries:", ":cookie:", ":two:", ":four_leaf_clover:", ":cyclone:", ":sunflower:", ":six:", ":mushroom:", ":heart:", ":snowflake:"]
|
reel_pattern = [":cherries:", ":cookie:", ":two:", ":four_leaf_clover:",
|
||||||
padding_before = [":mushroom:", ":heart:", ":snowflake:"] # padding prevents index errors
|
":cyclone:", ":sunflower:", ":six:", ":mushroom:", ":heart:", ":snowflake:"]
|
||||||
|
# padding prevents index errors
|
||||||
|
padding_before = [":mushroom:", ":heart:", ":snowflake:"]
|
||||||
padding_after = [":cherries:", ":cookie:", ":two:"]
|
padding_after = [":cherries:", ":cookie:", ":two:"]
|
||||||
reel = padding_before + reel_pattern + padding_after
|
reel = padding_before + reel_pattern + padding_after
|
||||||
reels = []
|
reels = []
|
||||||
for i in range(0, 3):
|
for i in range(0, 3):
|
||||||
n = randint(3,12)
|
n = randint(3, 12)
|
||||||
reels.append([reel[n - 1], reel[n], reel[n + 1]])
|
reels.append([reel[n - 1], reel[n], reel[n + 1]])
|
||||||
line = [reels[0][1], reels[1][1], reels[2][1]]
|
line = [reels[0][1], reels[1][1], reels[2][1]]
|
||||||
|
|
||||||
display_reels = "~~\n~~ " + reels[0][0] + " " + reels[1][0] + " " + reels[2][0] + "\n"
|
display_reels = "~~\n~~ " + \
|
||||||
display_reels += ">" + reels[0][1] + " " + reels[1][1] + " " + reels[2][1] + "\n"
|
reels[0][0] + " " + reels[1][0] + " " + reels[2][0] + "\n"
|
||||||
display_reels += " " + reels[0][2] + " " + reels[1][2] + " " + reels[2][2] + "\n"
|
display_reels += ">" + reels[0][1] + " " + \
|
||||||
|
reels[1][1] + " " + reels[2][1] + "\n"
|
||||||
|
display_reels += " " + reels[0][2] + " " + \
|
||||||
|
reels[1][2] + " " + reels[2][2] + "\n"
|
||||||
|
|
||||||
if line[0] == ":two:" and line[1] == ":two:" and line[2] == ":six:":
|
if line[0] == ":two:" and line[1] == ":two:" and line[2] == ":six:":
|
||||||
bid = bid * 5000
|
bid = bid * 5000
|
||||||
slotMsg = "{}{} 226! Your bet is multiplied * 5000! {}! ".format(display_reels, message.author.mention, str(bid))
|
slotMsg = "{}{} 226! Your bet is multiplied * 5000! {}! ".format(
|
||||||
|
display_reels, message.author.mention, str(bid))
|
||||||
elif line[0] == ":four_leaf_clover:" and line[1] == ":four_leaf_clover:" and line[2] == ":four_leaf_clover:":
|
elif line[0] == ":four_leaf_clover:" and line[1] == ":four_leaf_clover:" and line[2] == ":four_leaf_clover:":
|
||||||
bid += 1000
|
bid += 1000
|
||||||
slotMsg = "{}{} Three FLC! +1000! ".format(display_reels, message.author.mention)
|
slotMsg = "{}{} Three FLC! +1000! ".format(
|
||||||
|
display_reels, message.author.mention)
|
||||||
elif line[0] == ":cherries:" and line[1] == ":cherries:" and line[2] == ":cherries:":
|
elif line[0] == ":cherries:" and line[1] == ":cherries:" and line[2] == ":cherries:":
|
||||||
bid += 800
|
bid += 800
|
||||||
slotMsg = "{}{} Three cherries! +800! ".format(display_reels, message.author.mention)
|
slotMsg = "{}{} Three cherries! +800! ".format(
|
||||||
|
display_reels, message.author.mention)
|
||||||
elif line[0] == line[1] == line[2]:
|
elif line[0] == line[1] == line[2]:
|
||||||
bid += 500
|
bid += 500
|
||||||
slotMsg = "{}{} Three symbols! +500! ".format(display_reels, message.author.mention)
|
slotMsg = "{}{} Three symbols! +500! ".format(
|
||||||
|
display_reels, message.author.mention)
|
||||||
elif line[0] == ":two:" and line[1] == ":six:" or line[1] == ":two:" and line[2] == ":six:":
|
elif line[0] == ":two:" and line[1] == ":six:" or line[1] == ":two:" and line[2] == ":six:":
|
||||||
bid = bid * 4
|
bid = bid * 4
|
||||||
slotMsg = "{}{} 26! Your bet is multiplied * 4! {}! ".format(display_reels, message.author.mention, str(bid))
|
slotMsg = "{}{} 26! Your bet is multiplied * 4! {}! ".format(
|
||||||
|
display_reels, message.author.mention, str(bid))
|
||||||
elif line[0] == ":cherries:" and line[1] == ":cherries:" or line[1] == ":cherries:" and line[2] == ":cherries:":
|
elif line[0] == ":cherries:" and line[1] == ":cherries:" or line[1] == ":cherries:" and line[2] == ":cherries:":
|
||||||
bid = bid * 3
|
bid = bid * 3
|
||||||
slotMsg = "{}{} Two cherries! Your bet is multiplied * 3! {}! ".format(display_reels, message.author.mention, str(bid))
|
slotMsg = "{}{} Two cherries! Your bet is multiplied * 3! {}! ".format(
|
||||||
|
display_reels, message.author.mention, str(bid))
|
||||||
elif line[0] == line[1] or line[1] == line[2]:
|
elif line[0] == line[1] or line[1] == line[2]:
|
||||||
bid = bid * 2
|
bid = bid * 2
|
||||||
slotMsg = "{}{} Two symbols! Your bet is multiplied * 2! {}! ".format(display_reels, message.author.mention, str(bid))
|
slotMsg = "{}{} Two symbols! Your bet is multiplied * 2! {}! ".format(
|
||||||
|
display_reels, message.author.mention, str(bid))
|
||||||
else:
|
else:
|
||||||
slotMsg = "{}{} Nothing! Lost bet. ".format(display_reels, message.author.mention)
|
slotMsg = "{}{} Nothing! Lost bet. ".format(
|
||||||
|
display_reels, message.author.mention)
|
||||||
self.bank.withdraw_credits(message.author, bid)
|
self.bank.withdraw_credits(message.author, bid)
|
||||||
slotMsg += "\n" + " Credits left: {}".format(self.bank.get_balance(message.author))
|
slotMsg += "\n" + \
|
||||||
|
" Credits left: {}".format(
|
||||||
|
self.bank.get_balance(message.author))
|
||||||
await self.bot.send_message(message.channel, slotMsg)
|
await self.bot.send_message(message.channel, slotMsg)
|
||||||
return True
|
return True
|
||||||
self.bank.deposit_credits(message.author, bid)
|
self.bank.deposit_credits(message.author, bid)
|
||||||
slotMsg += "\n" + " Current credits: {}".format(self.bank.get_balance(message.author))
|
slotMsg += "\n" + \
|
||||||
|
" Current credits: {}".format(
|
||||||
|
self.bank.get_balance(message.author))
|
||||||
await self.bot.send_message(message.channel, slotMsg)
|
await self.bot.send_message(message.channel, slotMsg)
|
||||||
|
|
||||||
@commands.group(pass_context=True, no_pm=True)
|
@commands.group(pass_context=True, no_pm=True)
|
||||||
@ -465,7 +519,7 @@ class Economy:
|
|||||||
await self.bot.say(msg)
|
await self.bot.say(msg)
|
||||||
|
|
||||||
@economyset.command(pass_context=True)
|
@economyset.command(pass_context=True)
|
||||||
async def slotmin(self, ctx, bid : int):
|
async def slotmin(self, ctx, bid: int):
|
||||||
"""Minimum slot machine bid"""
|
"""Minimum slot machine bid"""
|
||||||
server = ctx.message.server
|
server = ctx.message.server
|
||||||
self.settings[server.id]["SLOT_MIN"] = bid
|
self.settings[server.id]["SLOT_MIN"] = bid
|
||||||
@ -473,7 +527,7 @@ class Economy:
|
|||||||
dataIO.save_json(self.file_path, self.settings)
|
dataIO.save_json(self.file_path, self.settings)
|
||||||
|
|
||||||
@economyset.command(pass_context=True)
|
@economyset.command(pass_context=True)
|
||||||
async def slotmax(self, ctx, bid : int):
|
async def slotmax(self, ctx, bid: int):
|
||||||
"""Maximum slot machine bid"""
|
"""Maximum slot machine bid"""
|
||||||
server = ctx.message.server
|
server = ctx.message.server
|
||||||
self.settings[server.id]["SLOT_MAX"] = bid
|
self.settings[server.id]["SLOT_MAX"] = bid
|
||||||
@ -481,7 +535,7 @@ class Economy:
|
|||||||
dataIO.save_json(self.file_path, self.settings)
|
dataIO.save_json(self.file_path, self.settings)
|
||||||
|
|
||||||
@economyset.command(pass_context=True)
|
@economyset.command(pass_context=True)
|
||||||
async def slottime(self, ctx, seconds : int):
|
async def slottime(self, ctx, seconds: int):
|
||||||
"""Seconds between each slots use"""
|
"""Seconds between each slots use"""
|
||||||
server = ctx.message.server
|
server = ctx.message.server
|
||||||
self.settings[server.id]["SLOT_TIME"] = seconds
|
self.settings[server.id]["SLOT_TIME"] = seconds
|
||||||
@ -489,7 +543,7 @@ class Economy:
|
|||||||
dataIO.save_json(self.file_path, self.settings)
|
dataIO.save_json(self.file_path, self.settings)
|
||||||
|
|
||||||
@economyset.command(pass_context=True)
|
@economyset.command(pass_context=True)
|
||||||
async def paydaytime(self, ctx, seconds : int):
|
async def paydaytime(self, ctx, seconds: int):
|
||||||
"""Seconds between each payday"""
|
"""Seconds between each payday"""
|
||||||
server = ctx.message.server
|
server = ctx.message.server
|
||||||
self.settings[server.id]["PAYDAY_TIME"] = seconds
|
self.settings[server.id]["PAYDAY_TIME"] = seconds
|
||||||
@ -497,13 +551,14 @@ class Economy:
|
|||||||
dataIO.save_json(self.file_path, self.settings)
|
dataIO.save_json(self.file_path, self.settings)
|
||||||
|
|
||||||
@economyset.command(pass_context=True)
|
@economyset.command(pass_context=True)
|
||||||
async def paydaycredits(self, ctx, credits : int):
|
async def paydaycredits(self, ctx, credits: int):
|
||||||
"""Credits earned each payday"""
|
"""Credits earned each payday"""
|
||||||
server = ctx.message.server
|
server = ctx.message.server
|
||||||
self.settings[server.id]["PAYDAY_CREDITS"] = credits
|
self.settings[server.id]["PAYDAY_CREDITS"] = credits
|
||||||
await self.bot.say("Every payday will now give " + str(credits) + " credits.")
|
await self.bot.say("Every payday will now give " + str(credits) + " credits.")
|
||||||
dataIO.save_json(self.file_path, self.settings)
|
dataIO.save_json(self.file_path, self.settings)
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
@economyset.command(pass_context=True)
|
@economyset.command(pass_context=True)
|
||||||
async def registercredits(self, ctx, credits : int):
|
async def registercredits(self, ctx, credits : int):
|
||||||
"""Credits given on registering an account"""
|
"""Credits given on registering an account"""
|
||||||
@ -516,12 +571,17 @@ class Economy:
|
|||||||
|
|
||||||
def display_time(self, seconds, granularity=2): # What would I ever do without stackoverflow?
|
def display_time(self, seconds, granularity=2): # What would I ever do without stackoverflow?
|
||||||
intervals = ( # Source: http://stackoverflow.com/a/24542445
|
intervals = ( # Source: http://stackoverflow.com/a/24542445
|
||||||
|
=======
|
||||||
|
# What would I ever do without stackoverflow?
|
||||||
|
def display_time(self, seconds, granularity=2):
|
||||||
|
intervals = ( # Source: http://stackoverflow.com/a/24542445
|
||||||
|
>>>>>>> cb472f9... Some PEP8 stuff
|
||||||
('weeks', 604800), # 60 * 60 * 24 * 7
|
('weeks', 604800), # 60 * 60 * 24 * 7
|
||||||
('days', 86400), # 60 * 60 * 24
|
('days', 86400), # 60 * 60 * 24
|
||||||
('hours', 3600), # 60 * 60
|
('hours', 3600), # 60 * 60
|
||||||
('minutes', 60),
|
('minutes', 60),
|
||||||
('seconds', 1),
|
('seconds', 1),
|
||||||
)
|
)
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
@ -559,9 +619,12 @@ def setup(bot):
|
|||||||
check_folders()
|
check_folders()
|
||||||
check_files()
|
check_files()
|
||||||
logger = logging.getLogger("red.economy")
|
logger = logging.getLogger("red.economy")
|
||||||
if logger.level == 0: # Prevents the logger from being loaded again in case of module reload
|
if logger.level == 0:
|
||||||
|
# Prevents the logger from being loaded again in case of module reload
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
handler = logging.FileHandler(filename='data/economy/economy.log', encoding='utf-8', mode='a')
|
handler = logging.FileHandler(
|
||||||
handler.setFormatter(logging.Formatter('%(asctime)s %(message)s', datefmt="[%d/%m/%Y %H:%M]"))
|
filename='data/economy/economy.log', encoding='utf-8', mode='a')
|
||||||
|
handler.setFormatter(logging.Formatter(
|
||||||
|
'%(asctime)s %(message)s', datefmt="[%d/%m/%Y %H:%M]"))
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
bot.add_cog(Economy(bot))
|
bot.add_cog(Economy(bot))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user