Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #35 from wrkzcoin/minor-fixed
Browse files Browse the repository at this point in the history
Minor fixed 2023
  • Loading branch information
wrkzdev authored Dec 31, 2023
2 parents 0db908a + 1ccd2d1 commit 20632dd
Show file tree
Hide file tree
Showing 20 changed files with 583 additions and 1,411 deletions.
1 change: 1 addition & 0 deletions wrkzcoin_tipbot/Bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ async def logchanbot(content: str):
bot.erc_node_list = {
"FTM": bot.config['default_endpoints']['ftm'],
"BSC": bot.config['default_endpoints']['bsc'],
"BNB": bot.config['default_endpoints']['bsc'],
"MATIC": bot.config['default_endpoints']['matic'],
"xDai":bot.config['default_endpoints']['xdai'],
"ETH": bot.config['default_endpoints']['eth'],
Expand Down
17 changes: 13 additions & 4 deletions wrkzcoin_tipbot/api-helper/solana/fastapi-solana.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ async def fetch_wallet_balance(url: str, address: str, timeout: int=60):
traceback.print_exc(file=sys.stdout)
return None

async def send_solana(url: str, from_key: str, to_address: str, atomic_amount: int, timeout: int=60):
async def send_solana(url: str, from_address: str, from_key: str, to_address: str, atomic_amount: int, timeout: int=60):
try:
sender = Keypair.from_bytes(bytes.fromhex(from_key))
# check if 32 or 64
byte_key = bytes.fromhex(from_key)
if len(byte_key) == 32:
public_key = Pubkey.from_string(from_address)
byte_key += bytes(public_key)

sender = Keypair.from_bytes(byte_key)
print("{} SOL trying to send from {} to {}, lamports={}".format(
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), sender.pubkey(), to_address, atomic_amount

Expand Down Expand Up @@ -119,8 +125,9 @@ async def post_verify_account_token(
async def post_create_account_token(
url: str, token_address: str, owner_address: str, program_id: str, from_key: str, timeout: int=60
):
# Not use?
try:
async with AsyncClient(url, timeout=timeout) as client:
async with AsyncClient(url, timeout=timeout) as client:
spl_client = AsyncToken(
conn=client,
pubkey=Pubkey.from_string(token_address),
Expand Down Expand Up @@ -226,6 +233,7 @@ class Address(BaseModel):

class TxData(BaseModel):
endpoint: str
from_address: str
from_key: str
to_addr: str
atomic_amount: int
Expand Down Expand Up @@ -511,7 +519,8 @@ async def send_transaction(item: TxData):
"timestamp": int(time.time())
}
else:
sending = await send_solana(item.endpoint, item.from_key, item.to_addr, item.atomic_amount, 60)
print(item.endpoint, item.from_key, item.to_addr, item.atomic_amount, 60)
sending = await send_solana(item.endpoint, item.from_address, item.from_key, item.to_addr, item.atomic_amount, 60)
return {
"success": True,
"hash": str(sending),
Expand Down
2 changes: 2 additions & 0 deletions wrkzcoin_tipbot/api-helper/tezos/fastapi-tezos.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ async def get_balance_token_tezos(
print("tezos_check_token_balances: return {}".format(response.status))
except asyncio.exceptions.TimeoutError:
print("Tezos check balances timeout for url: {} / addr: {}. Time: {}".format(item.endpoint, item.address, item.timeout))
except aiohttp.client_exceptions.ContentTypeError:
print("Tezos Content type error: ", response)
except Exception:
traceback.print_exc(file=sys.stdout)
return {
Expand Down
73 changes: 69 additions & 4 deletions wrkzcoin_tipbot/cogs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def __init__(self, bot):
self.local_db_extra = None
self.pool_local_db_extra = None
self.old_message_data_age = 60 * 24 * 3600 # max. 2 month
self.enable_logchan = True
self.botLogChan = None

async def bot_log(self):
if self.botLogChan is None:
self.botLogChan = self.bot.get_channel(self.bot.LOG_CHAN)

async def openConnection_extra(self):
if self.local_db_extra is None:
Expand Down Expand Up @@ -1033,9 +1039,12 @@ async def updatebalance(self, ctx, coin: str):
chain_id = getattr(getattr(self.bot.coin_list, coin_name), "chain_id")
start_time = time.time()
if type_coin == "ERC-20":
endpoint = self.bot.erc_node_list[net_name]
if self.bot.erc_node_list.get(net_name + "_WITHDRAW"):
endpoint = self.bot.erc_node_list[net_name + "_WITHDRAW"]
check_min_deposit = functools.partial(
sql_check_minimum_deposit_erc20,
self.bot.erc_node_list[net_name],
endpoint,
net_name, coin_name,
contract, coin_decimal,
min_move_deposit, min_gas_tx,
Expand Down Expand Up @@ -1326,7 +1335,7 @@ async def call_ada_delete_wallet(url_wallet_id: str, timeout=60):
DELETE FROM `ada_wallets` WHERE `wallet_id`=%s LIMIT 1 """
await cur.execute(sql, (wallet_id, wallet_id))
await conn.commit()
msg = f"{ctx.author.mention}, sucessfully delete wallet `{wallet_name}` | `{wallet_id}`."
msg = f"{ctx.author.mention}, successfully delete wallet `{wallet_name}` | `{wallet_id}`."
await ctx.reply(msg)
return
except Exception:
Expand Down Expand Up @@ -1783,6 +1792,14 @@ async def auditcoin(self, ctx, coin: str):
list_users = [m.id for m in self.bot.get_all_members()]
list_guilds = [g.id for g in self.bot.guilds]
already_checked = []
# find LP
find_other_lp = await self.wallet_api.cexswap_get_all_poolshares(user_id=None, ticker=coin_name)
total_pool_coin = 0
for i in find_other_lp:
if i['ticker_1_name'] == coin_name:
total_pool_coin += i['amount_ticker_1']
elif i['ticker_2_name'] == coin_name:
total_pool_coin += i['amount_ticker_2']
if len(all_user_id) > 0:
msg = f"{ctx.author.mention}, {EMOJI_INFORMATION} **{coin_name}** there are "\
f"total {str(len(all_user_id))} user records. Wait a big while..."
Expand Down Expand Up @@ -1872,7 +1889,9 @@ async def auditcoin(self, ctx, coin: str):
traceback.print_exc(file=sys.stdout)
msg_checkcoin += wallet_stat_str + "\n"
msg_checkcoin += "Total record id in DB: " + str(sum_user) + "\n"
msg_checkcoin += "Total balance: " + num_format_coin(sum_balance) + " " + coin_name + "\n"
msg_checkcoin += "Total usable balance: " + num_format_coin(sum_balance) + " " + coin_name + "\n"
msg_checkcoin += "Locked in LP: " + num_format_coin(total_pool_coin) + " " + coin_name + "\n"
msg_checkcoin += "Total balance: " + num_format_coin(sum_balance + float(total_pool_coin)) + " " + coin_name + "\n"
msg_checkcoin += "Total user/guild not found (discord): " + str(sum_unfound_user) + "\n"
msg_checkcoin += "Total balance not found (discord): " + num_format_coin(
sum_unfound_balance) + " " + coin_name + "\n"
Expand Down Expand Up @@ -2533,7 +2552,53 @@ async def rewardtask(self, ctx, coin: str):
coin_list_name = await self.get_coin_list_name()
if coin_list_name:
self.bot.coin_name_list = coin_list_name


@commands.is_owner()
@admin.command(
hidden=True,
usage="featurerole <guild id>",
description="Enable/Disable feature role of a guild"
)
async def featurerole(self, ctx, guild_id: str):
try:
await self.bot_log()
serverinfo = self.bot.other_data['guild_list'].get(guild_id)
if serverinfo is None:
await ctx.reply(f"{ctx.author.mention}, guild ID {guild_id} is not in the database.")
return
else:
get_guild = self.bot.get_guild(int(guild_id))
if get_guild is None:
await ctx.reply(f"{ctx.author.mention}, Bot can't get guild info for guild ID {guild_id}.")
return

if serverinfo and serverinfo['enable_featurerole'] == 1:
await store.sql_changeinfo_by_server(guild_id, 'enable_featurerole', 0)
if self.enable_logchan:
await self.botLogChan.send(
f"{ctx.author.name} / {ctx.author.id} DISABLE featurerole in guild {get_guild.name} / {get_guild.id}."
)
await ctx.reply(f"{ctx.author.mention}, successfully disable featurerole in {get_guild.name} / {get_guild.id}.")
# re-load guild list
await self.utils.bot_reload_guilds()
return
elif serverinfo and serverinfo['enable_featurerole'] == 0:
await store.sql_changeinfo_by_server(guild_id, 'enable_featurerole', 1)
if self.enable_logchan:
await self.botLogChan.send(
f"{ctx.author.name} / {ctx.author.id} ENABLE featurerole in guild {get_guild.name} / {get_guild.id}"
)
await ctx.reply(f"{ctx.author.mention}, successfully enable featurerole in {get_guild.name} / {get_guild.id}.")
# re-load guild list
await self.utils.bot_reload_guilds()
return
else:
await ctx.reply(f"{ctx.author.mention}, internal error.")
return
except Exception:
traceback.print_exc(file=sys.stdout)
await ctx.reply(f"{ctx.author.mention}, internal error.")

@commands.is_owner()
@admin.command(
hidden=True,
Expand Down
Loading

0 comments on commit 20632dd

Please sign in to comment.