diff --git a/projects/Team-5-IFipBot/IOSG Layer2 Hackathon - IFTip Bot.pptx b/projects/Team-5-IFipBot/IOSG Layer2 Hackathon - IFTip Bot.pptx new file mode 100644 index 0000000..b01c171 Binary files /dev/null and b/projects/Team-5-IFipBot/IOSG Layer2 Hackathon - IFTip Bot.pptx differ diff --git a/projects/Team-5-IFipBot/README.txt b/projects/Team-5-IFipBot/README.txt new file mode 100644 index 0000000..0b03465 --- /dev/null +++ b/projects/Team-5-IFipBot/README.txt @@ -0,0 +1,35 @@ +*Team name +IFTip Bot + +*Product direction +A Telegram & Discord Tip Bot supports Near Aurora (ETH & ERC20 Tokens) + +*Introduction +IFTip Bot create HD wallet by create random mnemonic words for each user. We integrate Aurora's wallet and contract interaction in IFTip Bot, and supports actions on Aurora: + +1. Create wallet in very low threshold +2. Tip friends with Aurora ETH & ERC20 Tokens +3. Airdrop red packets to group users +4. Query price of Near and other tokens + +*Github link +https://github.com/bibodeng/Layer2Hackathon + +*Demo link +Telegram Bot: https://t.me/iftip_bot +Discord Bot: https://dsc.gg/iftip-bot +Demo Video: https://sourl.cn/rQnsMq + +*Ethereum Wallet Address +0x798953fF89C0cDDe6681977c9b7321eFE1E87d0e + +Twitter handle +@bibodeng + +Website +https://iftip.io + +Team information +Let us know your team composition and everyone's responsibility + +[ A ] bibodeng, product manager and programmer diff --git a/projects/Team-5-IFipBot/iftip_bot/telegram/__init__.py b/projects/Team-5-IFipBot/iftip_bot/telegram/__init__.py new file mode 100644 index 0000000..4196b96 --- /dev/null +++ b/projects/Team-5-IFipBot/iftip_bot/telegram/__init__.py @@ -0,0 +1,126 @@ +import re +import hashlib + +from sqlalchemy import or_ +from sqlalchemy import and_ + +from flask import current_app +from telegram.ext import Updater +from telegram.ext import CommandHandler +from telegram.ext import MessageHandler +from telegram.ext import Filters + +from app.ext import db +from app.models import * +from app.utils import asset +from app.utils import ifwallet +from app.utils import reg as reg_utils +from app.utils.utils import * +from app.utils import cet +from app.utils import cet_dex +from app.utils import coin_exchange +from app.utils.cmc import get_price_cmc +from app.utils.telegram_sdk import get_chat_member_count +from app.utils.telegram_sdk import get_chat_administrators +from app.utils.exceptions import BusinessError + +from app.utils.enums.coin_type import CoinType +from app.utils.enums.coin_type import Blockchain +from app.utils.enums.currency_type import CurrencyType + +platform = 'telegram' +default_coin_type = 'ETH-AURORA' + +def command_help(update, context): + add_group_member(update) + if len(context.args) == 1: + topic = context.args[0] + if topic == 'price': + handle_price_help(update) + elif topic == 'deposit': + handle_deposit_help(update) + elif topic == 'withdraw': + handle_withdraw_help(update) + elif topic == 'tip': + handle_tip_help(update) + elif topic == 'rain': + handle_rain_help(update) + elif topic == 'password': + handle_password_help(update) + elif topic == 'pair': + handle_swap_pair_help(update) + elif topic == 'swap': + handle_swap_help(update) + elif topic == 'bind_mobile': + handle_bind_mobile_help(update) + elif topic == 'verify_mobile': + handle_verify_mobile_help(update) + elif topic == 'switch_wallet': + handle_switch_wallet_help(update) + + return + +def command_deposit(update, context): + add_group_member(update) + + if context.args: + coin_type = context.args[0].upper() + datas = {'coin': coin_type} + handle_deposit(update, datas) + else: + handle_deposit_help(update) + +def command_withdraw(update, context): + add_group_member(update) + if context.args: + datas = { + "amount": quantize(context.args[0], 8), + "coin": context.args[1], + "address": context.args[2], + "memo": context.args[3] if len(context.args) == 4 else None + } + handle_withdraw(update, datas) + else: + handle_withdraw_help(update) + +def command_balance(update, context): + add_group_member(update) + if context.args: + datas = {'coin': context.args[0]} + handle_balance(update, datas) + else: + handle_balance(update, datas={}) + +def command_tip(update, context): + add_group_member(update) + handle_tip_help(update) + +def command_rain(update, context): + try: + add_group_member(update) + if len(context.args) == 4: + datas = { + 'share': context.args[0], + 'amount': context.args[2], + 'coin': context.args[3] + } + handle_rain(update, datas) + else: + handle_rain_help(update) + except: + current_app.logger.exception('command_rain fail') + +def command_password_red_packet(update, context): + add_group_member(update) + if len(context.args) == 5: + datas = { + 'share': context.args[0], + 'amount': context.args[2], + 'coin': context.args[3], + 'password': context.args[4].replace('#', '') + } + handle_password_red_packet(update, datas) + else: + handle_password_help(update) + + diff --git a/projects/Team-5-IFipBot/iftip_bot/telegram/robot_reg.py b/projects/Team-5-IFipBot/iftip_bot/telegram/robot_reg.py new file mode 100644 index 0000000..a07e1c8 --- /dev/null +++ b/projects/Team-5-IFipBot/iftip_bot/telegram/robot_reg.py @@ -0,0 +1,409 @@ +import re + +def intention_dbs(): + dbs = [ + { + "reg": "^(介绍|开始|机器人|start)$", + "key": "handle_start", + "default": None, + "dics": None, + }, + # ---------------help-------------- + { + "reg": "^(帮助|help)$", + "key": "handle_help", + "default": None, + "dics": None, + }, + { + "reg": "^(我想|我要|怎么|如何)?(提现|提走|提币|withdraw)[ ]?([a-zA-Z0-9\-]{2,16})?$", + "key": "handle_withdraw_help", + "default": None, + "dics": None, + }, + { + "reg": "^(充值|deposit)$", + "key": "handle_deposit_help", + "default": None, + "dics": None, + }, + { + "reg": "^(钱包|wallet|wallets|钱包列表)$", + "key": "handle_wallet_list", + "default": None, + "dics": None, + }, + { + "reg": "^(我想|我要|怎么|帮助|help)[ ]?(报价|充值|提现|提币|打赏|红包|发红包|红包雨|口令红包|兑换|交易对|绑定|绑定手机|验证|绑定验证|手机验证|切换钱包|price|deposit|withdraw|tip|rain|password|pair|swap|bind_mobile|verify_mobile|switch_wallet)$", + "key": "handle_help", + "default": None, + "dics": [{ + "reg": "^(我想|我要|怎么|帮助|help)[ ]?(报价|充值|提现|提币|打赏|红包|发红包|红包雨|口令红包|兑换|交易对|绑定|绑定手机|验证|绑定验证|手机验证|切换钱包|price|deposit|withdraw|tip|rain|password|pair|swap|bind_mobile|verify_mobile|switch_wallet)$", + "is_read_keys": True, + "slot_keys": [ + {"field": "fix", "default": None}, + {"field": "help", "default": None} + ], + "key": "handle_help", + "keys": [ + {"name": "报价", "key": "handle_price_help"}, + {"name": "充值", "key": "handle_deposit_help"}, + {"name": "提现", "key": "handle_withdraw_help"}, + {"name": "提币", "key": "handle_withdraw_help"}, + {"name": "打赏", "key": "handle_tip_help"}, + {"name": "红包", "key": "handle_rain_help"}, + {"name": "发红包", "key": "handle_rain_help"}, + {"name": "红包雨", "key": "handle_rain_help"}, + {"name": "口令红包", "key": "handle_password_help"}, + {"name": "兑换", "key": "handle_swap_help"}, + {"name": "交易对", "key": "handle_swap_pair_help"}, + {"name": "绑定", "key": "handle_bind_mobile_help"}, + {"name": "绑定手机", "key": "handle_bind_mobile_help"}, + {"name": "验证", "key": "handle_verify_mobile_help"}, + {"name": "绑定验证", "key": "handle_verify_mobile_help"}, + {"name": "手机验证", "key": "handle_verify_mobile_help"}, + {"name": "切换钱包", "key": "handle_switch_wallet_help"}, + {"name": "price", "key": "handle_price_help"}, + {"name": "deposit", "key": "handle_deposit_help"}, + {"name": "withdraw", "key": "handle_withdraw_help"}, + {"name": "tip", "key": "handle_tip_help"}, + {"name": "rain", "key": "handle_rain_help"}, + {"name": "password", "key": "handle_password_help"}, + {"name": "pair", "key": "handle_swap_pair_help"}, + {"name": "swap", "key": "handle_swap_help"}, + {"name": "bind_mobile", "key": "handle_bind_mobile_help"}, + {"name": "verify_mobile", "key": "handle_verify_mobile_help"}, + {"name": "switch_wallet", "key": "handle_switch_wallet_help"}, + ], + }] + }, + { + "reg": "^(我想|我要|怎么|帮助|help)?[ ]?(报价|充值|提现|提币|打赏|红包|口令红包|兑换|绑定|绑定手机|验证|绑定验证|手机验证|切换钱包|price|deposit|withdraw|tip|password|pair|swap|bind_mobile|verify_mobile|switch_wallet)$", + "key": "handle_help", + "default": None, + "dics": [{ + "reg": "^(我想|我要|怎么|帮助|help)?[ ]?(报价|充值|提现|提币|打赏|红包|口令红包|兑换|交易对|绑定|绑定手机|验证|绑定验证|手机验证|切换钱包|price|deposit|withdraw|tip|password|pair|swap|bind_mobile|verify_mobile|switch_wallet)$", + "is_read_keys": True, + "slot_keys": [ + {"field": "fix", "default": None}, + {"field": "help", "default": None} + ], + "key": "handle_help", + "keys": [ + {"name": "报价", "key": "handle_price_help"}, + {"name": "充值", "key": "handle_deposit_help"}, + {"name": "提现", "key": "handle_withdraw_help"}, + {"name": "提币", "key": "handle_withdraw_help"}, + {"name": "打赏", "key": "handle_tip_help"}, + {"name": "红包", "key": "handle_rain_help"}, + {"name": "口令红包", "key": "handle_password_help"}, + {"name": "兑换", "key": "handle_swap_help"}, + {"name": "交易对", "key": "handle_swap_pair_help"}, + {"name": "绑定", "key": "handle_bind_mobile_help"}, + {"name": "绑定手机", "key": "handle_bind_mobile_help"}, + {"name": "验证", "key": "handle_verify_mobile_help"}, + {"name": "绑定验证", "key": "handle_verify_mobile_help"}, + {"name": "手机验证", "key": "handle_verify_mobile_help"}, + {"name": "切换钱包", "key": "handle_switch_wallet_help"}, + {"name": "price", "key": "handle_price_help"}, + {"name": "deposit", "key": "handle_deposit_help"}, + {"name": "withdraw", "key": "handle_withdraw_help"}, + {"name": "tip", "key": "handle_tip_help"}, + {"name": "password", "key": "handle_password_help"}, + {"name": "pair", "key": "handle_swap_pair_help"}, + {"name": "swap", "key": "handle_swap_help"}, + {"name": "bind_mobile", "key": "handle_bind_mobile_help"}, + {"name": "verify_mobile", "key": "handle_verify_mobile_help"}, + {"name": "switch_wallet", "key": "handle_switch_wallet_help"}, + ], + }] + }, + # ------------balance------------- + { + "reg": "^(余额|balance)[ ]?([a-zA-Z0-9\-]{2,16})?$", + "key": "handle_balance", + "default": None, + "dics": [{ + "reg": "^(余额|balance)[ ]?([a-zA-Z0-9\-]{2,16})?$", + "slot_keys": [ + {"field": "fix", "default": None}, + {"field": "coin", "default": None} + ], + "key": "handle_balance", + "is_read_keys": False, + "keys": [] + }], + }, + { + "reg": "^(查看我的|查看|我的|查|check)*[ ]?([a-zA-Z0-9\-]{2,16})?[ ]?(余额|balance)$", + "key": "handle_balance", + "default": None, + "dics": [{ + "reg": "^(查看我的|查看|我的|查|check)*[ ]?([a-zA-Z0-9\-]{2,16})?[ ]?(余额|balance)$", + "slot_keys": [ + {"field": "fix", "default": None}, + {"field": "coin", "default": None}, + {"field": "action", "default": None} + ], + "key": "handle_balance", + "is_read_keys": False, + "keys": [] + }], + }, + # ---------------deposit--------------- + { + "reg": "^(我要|我想)?(充值|充值|充入|地址|address|deposit)[ ]?([a-zA-Z0-9\-]{2,16})?$", + "key": "handle_deposit", + "default": None, + "dics": [{ + "reg": "^(我要|我想)?(充值|充入|地址|address|deposit)[ ]?([a-zA-Z0-9\-]{2,16})?$", + "slot_keys": [ + {"field": "will", "default": None}, + {"field": "fix", "default": None}, + {"field": "coin", "default": "IFT"} + ], + "key": "handle_deposit", + "is_read_keys": False, + "keys": [] + }], + }, + # --------------withdraw------------- + { + "reg": "^(我想|我要|怎么|如何)?(提现|提走|提币|withdraw)[ ]?", + "key": None, + "default": None, + "dics": [{ + "reg": "^(我想|我要|怎么|如何)?(提现|提走|提币|withdraw)[ ]?([a-zA-Z0-9\-]{2,16})$", + "slot_keys": [], + "key": "handle_withdraw_help", + "is_read_keys": False, + "keys": [] + }, { + "reg": "^(我想|我要)?(提现|提走|提币|withdraw)[ ]?([+-]?\d+[\.\d]*)[ ]?([a-zA-Z0-9\-]{2,16})?[ ]+([a-zA-Z0-9:]{30,66})[ ]+([a-z0-9A-Z]{1,30})?$", + "slot_keys": [ + {"field": "will", "default": None}, + {"field": "fix", "default": None}, + {"field": "amount", "default": None}, + {"field": "coin", "default": None}, + {"field": "address", "default": None}, + {"field": "memo", "default": None}, + ], + "key": "handle_withdraw", + "is_read_keys": False, + "keys": [] + }, + { + "reg": "^(我想|我要)?(提现|提走|提币|withdraw)[ ]?(\d+[\.\d]*)[ ]?([a-zA-Z0-9\-]{2,16})[ ]?[到|到地址|to]?[ ]+([a-zA-Z0-9:]{30,66})[ ]?(memo|MEMO)?[ ]?([a-z0-9A-Z]{1,30})?$", + "slot_keys": [ + {"field": "will", "default": None}, + {"field": "fix", "default": None}, + {"field": "amount", "default": None}, + {"field": "coin", "default": None}, + {"field": "address", "default": None}, + {"field": "memo_title", "default": None}, + {"field": "memo", "default": None} + ], + "key": "handle_withdraw", + "is_read_keys": False, + "keys": [] + }] + }, + # --------------tip------------- + { + "reg": "^(打赏|tip|\+)[ ]?[\w\W]+", + "key": None, + "default": None, + "dics": [ + { + "reg": "^(打赏|tip|\+)[ ]?([+-]?\d+[\.\d]*)?[ ]?([a-zA-Z0-9\-]{2,16})?[ ]*$", + "slot_keys": [ + {"field": "fix", "default": None}, + {"field": "amount", "default": 1}, + {"field": "coin", "default": 'IFT'}, + ], + "key": "handle_reply_tip", + "is_read_keys": False, + "keys": [] + }, + { + "reg": "^(打赏|tip)[ ]?[@]?((?