async def tip(ctx, target_user: Union[discord.User, str], tip_amount: float, msg=None): if await isRegistered(ctx) == False: return if msg == None: msg = "Thank you for being a friend." # make this a random friendly message? if tip_amount < 1: await ctx.send("nice try... ") return with db.db_session: sender = db.User.get(name=username(ctx)) recipient = db.User.get(name=username(target_user)) if recipient == None: await ctx.send(f"invalid recipient...`{target_user}`") return # check funds points = db.getScore(sender) logger.debug(f'my points {points} tip amount {tip_amount}') if points < tip_amount: await ctx.send( f"You only have {points} points and can't send {tip_amount}..." ) return msg = msg[:100] tip = db.Transaction( sender=sender, recipient=recipient, value=tip_amount, type='tip', message=msg, ) db.commit() recipient_discord_user = await getDiscordUser(ctx, username(target_user)) message = f'<@{ctx.author.id}> is sending a tip of `{tip_amount}` points to <@{recipient_discord_user.id}> with message ```{msg}```' await ctx.send(message) if SETTINGS['_debug'] == True and SETTINGS['_debug_level'] == 1: logger.debug(f'{username(ctx)} - {message}')
def grant_points(self, user:str, amount:int): '''give points to a user from the byoctf_automaton. remember to use '"user#1234"' as the cmdline parameter for user''' with db.db_session: botuser = db.User.get(name=SETTINGS['_botusername']) user = db.User.get(name=user) if user: t = db.Transaction( sender=botuser, recipient=user, value=amount, type='admin grant', message='admin granted points' ) db.commit() print(f'granted {amount} points to {user.name}') else: print('invalid user')
def callback(): # Create a bot instance bot = utils.DuckBot(configloader.config["Telegram"]["token"]) # Test the specified token try: bot.get_me() except telegram.error.Unauthorized: print("The token you have entered in the config file is invalid.\n" "Fix it, then restart this script.") sys.exit(1) # Fetch the callback parameters secret = flask.request.args.get("secret") status = int(flask.request.args.get("status")) address = flask.request.args.get("addr") # Check the secret if secret == configloader.config["Bitcoin"]["secret"]: # Fetch the current transaction by address dbsession = db.Session() transaction = dbsession.query(db.BtcTransaction).filter( db.BtcTransaction.address == address).one_or_none() if transaction and transaction.txid == "": # Check the status if transaction.status == -1: current_time = datetime.datetime.now() timeout = 30 # If timeout has passed, use new btc price if current_time - datetime.timedelta( minutes=timeout) > datetime.datetime.strptime( transaction.timestamp, '%Y-%m-%d %H:%M:%S.%f'): transaction.price = Blockonomics.fetch_new_btc_price() transaction.timestamp = current_time transaction.status = 0 bot.send_message( transaction.user_id, "Payment recieved!\nYour account will be credited on confirmation." ) if status == 2: # Convert satoshi to fiat satoshi = float(flask.request.args.get("value")) received_btc = satoshi / 1.0e8 received_dec = round( Decimal(received_btc * transaction.price), int(configloader.config["Payments"]["currency_exp"])) received_float = float(received_dec) print("Recieved " + str(received_float) + " " + configloader.config["Payments"]["currency"] + " on address " + address) # Add the credit to the user account user = dbsession.query(db.User).filter( db.User.user_id == transaction.user_id).one_or_none() user.credit += int( received_float * (10**int(configloader.config["Payments"]["currency_exp"]))) # Add a transaction to list new_transaction = db.Transaction( user=user, value=int(received_float * (10**int( configloader.config["Payments"]["currency_exp"]))), provider="Bitcoin", notes=address) # Add and commit the transaction dbsession.add(new_transaction) # Update the received_value for address in DB transaction.value += received_float transaction.txid = flask.request.args.get("txid") transaction.status = 2 dbsession.commit() bot.send_message( transaction.user_id, "Payment confirmed!\nYour account has been credited with " + str(received_float) + " " + configloader.config["Payments"]["currency"] + ".") return "Success" else: dbsession.commit() return "Not enough confirmations" else: dbsession.commit() return "Transaction already proccessed" else: dbsession.commit() return "Incorrect secret"
import binance_apis import database import calculator import custom_logger import time import json # Initialise the objects db_transaction_obj = database.Transaction() db_bot_config_obj = database.BotConfig() db_price_data_obj = database.PriceData() # Initialise variables SLEEP_TIME = 5 action = None bot_config = db_bot_config_obj.get_bot_configs() coin_pair_symbol = bot_config['base_coin'] + bot_config['quote_coin'] # Main process loop while True: try: # Determine the action if action is None: last_buy_transaction = db_transaction_obj.get_last_buy_transaction( ) if last_buy_transaction is None: action = 'BUY' else: sell_transaction = db_transaction_obj.get_sell_transaction_by_buy_transaction( last_buy_transaction['id']) if last_buy_transaction['status'] != 'FILLED':