From 32ee91841542c0235ec9be8ea542bdab7ba80f9d Mon Sep 17 00:00:00 2001 From: un1xx Date: Mon, 10 Jun 2024 19:13:53 +0530 Subject: [PATCH] reformat --- botclass.py | 4 +- brahmos.py | 8 ++-- exts/REPL.py | 1 + exts/banking.py | 104 +++++++++++++++++++++------------------- exts/misc.py | 7 +-- utils/buttons/delete.py | 1 + utils/emojis.py | 3 +- utils/funcs.py | 10 +--- utils/paginator.py | 4 +- utils/transactions.py | 17 +++++++ 10 files changed, 88 insertions(+), 71 deletions(-) create mode 100644 utils/transactions.py diff --git a/botclass.py b/botclass.py index c353d10..e5a39f4 100644 --- a/botclass.py +++ b/botclass.py @@ -7,6 +7,7 @@ import aiohttp import discord import jishaku from discord.ext.commands import Bot, Context + from utils.paginator import Paginator, WebhookPaginator OWNER = json.load(open("store/cfg.json"))["ReplOwners"] @@ -18,7 +19,7 @@ class CustomCtx(Context): self.Paginator = Paginator self.WebhookPaginator = WebhookPaginator self.session = aiohttp.ClientSession(loop=self.bot.loop) - + async def paginate( self, pages: List[discord.Embed | str], @@ -28,7 +29,6 @@ class CustomCtx(Context): await self.Paginator(pages=pages, pagetype=pagetype).start(ctx=self, **kwargs) - class Brahmos(Bot): """ Custom bot class diff --git a/brahmos.py b/brahmos.py index bc95411..1529226 100644 --- a/brahmos.py +++ b/brahmos.py @@ -11,11 +11,12 @@ from typing import List, Literal, Optional, Union import aiofiles import discord import pytz -from botclass import CustomCtx, Brahmos from discord.ext import commands from jishaku.codeblocks import codeblock_converter from psutil import Process +from botclass import Brahmos, CustomCtx + try: import uvloop except: @@ -65,7 +66,7 @@ discord_format = Formatter("%(message)s") discord_handler = DiscordHandler( bot.name, webhook_url, - #avatar_url=, + # avatar_url=, ) # discord_handler = DiscordHandler("Happy Bot", webhook_url, emojis={}) @@ -105,7 +106,6 @@ class Main(commands.Cog): pass await ctx.send(content) - @commands.command(name="reload", hidden=True) @commands.is_owner() async def reloadexts(self, ctx: commands.Context): @@ -234,8 +234,6 @@ class Main(commands.Cog): await ctx.send(f"Synced the tree to {ret}/{len(guilds)}.") - - async def main(): async with bot: await bot.add_cog(Main(bot)) diff --git a/exts/REPL.py b/exts/REPL.py index eb3a4cd..eed3ea1 100644 --- a/exts/REPL.py +++ b/exts/REPL.py @@ -15,6 +15,7 @@ import aiofiles import aiohttp import discord from discord.ext import commands + from utils.paginator import Paginator ownerid = json.load(open("store/cfg.json"))["ReplOwners"] diff --git a/exts/banking.py b/exts/banking.py index 828f1eb..9f1bf5a 100644 --- a/exts/banking.py +++ b/exts/banking.py @@ -1,16 +1,18 @@ -import aiohttp import datetime import os import random from typing import List, Literal, Optional +import aiohttp import discord -from botclass import CustomCtx, Brahmos -from discord.ext import commands import pnwkit +from discord.ext import commands + +from botclass import Brahmos, CustomCtx from utils.base import BasicView from utils.emojis import Emojis + class Banking(commands.Cog): def __init__(self, bot: Brahmos): self.bot = bot @@ -18,9 +20,9 @@ class Banking(commands.Cog): api_key=os.getenv("pnwAPIKEY"), bot_key=os.getenv("pnwBOTKEY"), bot_key_api_key=os.getenv("pnwACCKEY"), - aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop) + aiohttp_session=aiohttp.ClientSession(loop=self.bot.loop), ) - + @commands.has_role(987770837627187250) @commands.command() async def tmilf(self, ctx: CustomCtx): @@ -31,73 +33,75 @@ class Banking(commands.Cog): resources = await self.kit.query( "alliances", {"id": 10177, "first": 1}, - "money, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel" + "money, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel", ) resources = resources.alliances[0] e = discord.Embed( color=discord.Color.yellow(), timestamp=datetime.datetime.utcnow(), - title="Approve Transaction" + title="Approve Transaction", + ) + e.description = ( + "Transferring resources to **Damn I Love Frogs**\n" + f"{Emojis.money} {resources.money:,}\n" + f"{Emojis.food} {resources.food:,}\n" + f"{Emojis.uranium} {resources.uranium:,}\n" + f"{Emojis.coal} {resources.coal:,}\n" + f"{Emojis.iron} {resources.iron:,}\n" + f"{Emojis.oil} {resources.oil:,}\n" + f"{Emojis.bauxite} {resources.bauxite:,}\n" + f"{Emojis.lead} {resources.lead:,}\n" + f"{Emojis.munitions} {resources.munitions:,}\n" + f"{Emojis.gasoline} {resources.gasoline:,}\n" + f"{Emojis.aluminum} {resources.aluminum:,}\n" + f"{Emojis.steel} {resources.steel:,}" ) - e.description = ("Transferring resources to **Damn I Love Frogs**\n" - f"{Emojis.money} {resources.money:,}\n" - f"{Emojis.food} {resources.food:,}\n" - f"{Emojis.uranium} {resources.uranium:,}\n" - f"{Emojis.coal} {resources.coal:,}\n" - f"{Emojis.iron} {resources.iron:,}\n" - f"{Emojis.oil} {resources.oil:,}\n" - f"{Emojis.bauxite} {resources.bauxite:,}\n" - f"{Emojis.lead} {resources.lead:,}\n" - f"{Emojis.munitions} {resources.munitions:,}\n" - f"{Emojis.gasoline} {resources.gasoline:,}\n" - f"{Emojis.aluminum} {resources.aluminum:,}\n" - f"{Emojis.steel} {resources.steel:,}" - ) - class View(BasicView): - def __init__(self, timeout: float | None = 60, clear: bool | None = False, kit: pnwkit.QueryKit = None): + def __init__( + self, + timeout: float | None = 60, + clear: bool | None = False, + kit: pnwkit.QueryKit = None, + ): super().__init__(timeout, clear) self.kit = kit - - - @discord.ui.button( - label="cancel", - style=discord.ButtonStyle.red - ) + + @discord.ui.button(label="cancel", style=discord.ButtonStyle.red) async def cancel(self, i: discord.Interaction, _): - await i.message.edit(content="> transaction cancelled", embed=None, view=None) + await i.message.edit( + content="> transaction cancelled", embed=None, view=None + ) self.stop() - - @discord.ui.button( - label="confirm", - style=discord.ButtonStyle.green - ) + + @discord.ui.button(label="confirm", style=discord.ButtonStyle.green) async def confirm(self, i: discord.Interaction, _): e.title = "Transaction Approved" e.description = e.description.replace("Transferring", "Transferred") e.color = discord.Color.green() await self.kit.mutation( "bankWithdraw", - {"receiver": 10198, - "receiver_type": 2, - "money" : resources.money, - "food" : resources.food, - "uranium" : resources.uranium, - "coal" : resources.coal, - "iron": resources.iron, - "oil" : resources.oil, - "bauxite" : resources.bauxite, - "lead" : resources.lead, - "munitions" : resources.munitions, - "gasoline" : resources.gasoline, - "aluminum" : resources.aluminum, - "steel" : resources.steel + { + "receiver": 10198, + "receiver_type": 2, + "money": resources.money, + "food": resources.food, + "uranium": resources.uranium, + "coal": resources.coal, + "iron": resources.iron, + "oil": resources.oil, + "bauxite": resources.bauxite, + "lead": resources.lead, + "munitions": resources.munitions, + "gasoline": resources.gasoline, + "aluminum": resources.aluminum, + "steel": resources.steel, }, - "id" + "id", ) await i.message.edit(embed=e, view=None) self.stop() + await ctx.send(embed=e, view=View(kit=self.kit)) diff --git a/exts/misc.py b/exts/misc.py index e68e6ec..33b715f 100644 --- a/exts/misc.py +++ b/exts/misc.py @@ -3,9 +3,10 @@ import random from typing import List, Literal, Optional import discord -from botclass import CustomCtx, Brahmos from discord.ext import commands +from botclass import Brahmos, CustomCtx + class Misc(commands.Cog): def __init__(self, bot: Brahmos): @@ -28,13 +29,13 @@ class Misc(commands.Cog): "yes", "not with u lmao", "in your dreams", - "no" + "no", ] num = random.randint(1, 10) reply = random.choice(replies_common) if num <= 2: - reply = replies_rare[random.randint(0,1)] + reply = replies_rare[random.randint(0, 1)] await ctx.send(reply) @commands.command(name="snowflake") diff --git a/utils/buttons/delete.py b/utils/buttons/delete.py index 718b470..0c06497 100644 --- a/utils/buttons/delete.py +++ b/utils/buttons/delete.py @@ -1,6 +1,7 @@ from typing import Optional import discord + from utils.base import BasicView diff --git a/utils/emojis.py b/utils/emojis.py index 35e6101..b83617d 100644 --- a/utils/emojis.py +++ b/utils/emojis.py @@ -1,5 +1,6 @@ from dataclasses import dataclass + class Emojis: food = "<:food:1220371848789753926>" aluminum = "<:aluminum:1220371851692343397>" @@ -12,4 +13,4 @@ class Emojis: uranium = "<:uranium:1220371869572796466>" oil = "<:oil:1220371873267843143>" coal = "<:coal:1220371877013229619>" - money = "<:dollarsym:1220378339970252841>" \ No newline at end of file + money = "<:dollarsym:1220378339970252841>" diff --git a/utils/funcs.py b/utils/funcs.py index 5ae9362..08ab1e7 100644 --- a/utils/funcs.py +++ b/utils/funcs.py @@ -6,19 +6,11 @@ from typing import List, Union import aiohttp import discord -TESTID = 356099868638445578 -ID = int(base64.b64decode(os.getenv("TOKEN").split(".")[0])) - - async def get_webhook( channel: Union[discord.TextChannel, discord.ForumChannel, discord.VoiceChannel] ) -> discord.Webhook: """Get a webhook created by bot in the channel""" - if ID != TESTID: - wname = "ゼロ" - else: - wname = "ゼロ~" - + wname = "brahmos" hooks: List[discord.Webhook] = await channel.webhooks() for hook in hooks: if hook.name == wname: diff --git a/utils/paginator.py b/utils/paginator.py index cb853d5..139928a 100644 --- a/utils/paginator.py +++ b/utils/paginator.py @@ -1,9 +1,11 @@ import asyncio from typing import List, Literal, Optional, Union -from discord import ButtonStyle, Embed, Interaction, Message, TextStyle, Webhook +from discord import (ButtonStyle, Embed, Interaction, Message, TextStyle, + Webhook) from discord.ext.commands import Bot, Context, errors from discord.ui import Button, Item, Modal, Select, TextInput, button + from utils.base import BasicView diff --git a/utils/transactions.py b/utils/transactions.py new file mode 100644 index 0000000..935a2a5 --- /dev/null +++ b/utils/transactions.py @@ -0,0 +1,17 @@ +import pnwkit + + +class Bank: + def __init__(self, kit: pnwkit.QueryKit): + self.kit = kit + + async def balance(self, id: int): + """ + receiver_type: + () + """ + resources = await self.kit.query( + "alliances", + {"id": 10177, "first": 1}, + "money, food, uranium, coal, iron, oil, bauxite, iron, lead, munitions, gasoline, aluminum, steel", + )