Пример #1
0
	def alert(bot,job): 
		try:
			cryptocompare = Commands.cryptocomparemsg()
			
			bot.sendMessage(chat_id=channels.channellist('stagingchannel'),text=cryptocompare,parse_mode='HTML')
		except:
			catcherror = traceback.format_exc()
			bot.sendMessage(chat_id=channels.channellist('errorchannel'), text=str(catcherror),parse_mode='HTML')
Пример #2
0
	def register(bot,update): #checks if usn exists.
		try:
			with closing(pymysql.connect(SQL.sqlinfo('host'),SQL.sqlinfo('usn'),SQL.sqlinfo('pw'),SQL.sqlinfo('db'),charset='utf8')) as conn:
				conn.autocommit(True)
				with closing(conn.cursor()) as cur:
					uid = update.message.from_user.id
					cur.execute("""SELECT telegram_id FROM mew WHERE telegram_id = %s""",(uid,))
					#if telegram ID does not exist, begin register process
					if cur.rowcount == 0: 
						message = "Hi! Lets get started by registering you with Hermes \n"
						message += "Can I have your name, please?\n"
						message += "To abort this process , please type /cancel"
						update.message.reply_text(message,parse_mode='HTML')
						#returns USERNAME, defined in states in hermes.
						return USERNAME 
					#else, TG username exist, update wallet ID?
					else: 
						message = "You are registered with Hermes.\n"
						message = "Would you like to update your wallet ID?\n"
						message += "Please reply with a yes or no (case-insensitive)"
						update.message.reply_text(message,parse_mode='HTML')
						#returns UPDATE, defined in states in hermes.
						return UPDATE 
		except:
			catcherror = traceback.format_exc()
			bot.sendMessage(chat_id=channels.channellist('errorchannel'), text=str(catcherror),parse_mode='HTML')
Пример #3
0
	def gem(bot,update):
		try:
			message = Commands.geminimsg()
			bot.sendMessage(chat_id=update.message.chat_id, text=message,parse_mode='HTML')
		except:
			catcherror = traceback.format_exc()
			bot.sendMessage(chat_id=channels.channellist('errorchannel'), text=str(catcherror),parse_mode='HTML')
Пример #4
0
	def removekb (bot,update):
		try:
			username = update.message.from_user.id
			if (channels.admin(username) == "admin"):
				message = "Removing all Inline Keyboards"
				update.message.reply_text(message,reply_markup=ReplyKeyboardRemove(),parse_mode='HTML')
			else:
				message = "I'm not the droid you're looking for, please contact an administrator to perform this command."
				update.message.reply_text(message,parse_mode='HTML')
		except:
			catcherror = traceback.format_exc()
			bot.sendMessage(chat_id=channels.channellist('errorchannel'), text=str(catcherror),parse_mode='HTML')
Пример #5
0
	def newwallet(bot,update):
		try:
			with closing(pymysql.connect(SQL.sqlinfo('host'),SQL.sqlinfo('usn'),SQL.sqlinfo('pw'),SQL.sqlinfo('db'),charset='utf8')) as conn:
				conn.autocommit(True)
				with closing(conn.cursor()) as cur:
					#if user has a uid registered, and wants to update their wallet addresses,
					message = "Please enter your new wallet address"
					update.message.reply_text(message,parse_mode='HTML')
					#goes back to wallet.
					return WALLET
		except:
			catcherror = traceback.format_exc()
			bot.sendMessage(chat_id=channels.channellist('errorchannel'), text=str(catcherror),parse_mode='HTML')
Пример #6
0
	def portfolio(bot,update):
		try:
			with closing(pymysql.connect(SQL.sqlinfo('host'),SQL.sqlinfo('usn'),SQL.sqlinfo('pw'),SQL.sqlinfo('db'),charset='utf8')) as conn:
				conn.autocommit(True)
				with closing(conn.cursor()) as cur:
					uid = update.message.from_user.id
					cur.execute("""SELECT * FROM mew WHERE telegram_id = %s""",(uid,))
					if cur.rowcount > 0:
						data = cur.fetchone()
						try:
							address = data[3]
						except:
							msg = "You do not have an address registered! Use /register to get registered"
							bot.sendMessage(chat_id=update.message.chat_id, text=msg,parse_mode='HTML')
						else:
							username = data[1]
							address = data[3]
							waitingmsg = "This will take approx 20-30seconds, please wait :)\n"
							waitingmsg += "Here's a baby seal to pass the time ◕ᴥ◕\n"
							waitingmsg += "While you are waiting, these are the steps that I'm using to calculate your portfolio\n"
							waitingmsg += "Firstly, I have a cronjob scraping MEW's github every 30min for token addresses\n"
							waitingmsg += "I then query your wallet address against Ethplorer's API to get a list of tokens\n"
							waitingmsg += "For accuracy's sake, I then use that list of tokens and match it against my database\n"
							waitingmsg += "I then use the token address retrieved from my database in etherscan's API to get the balance\n"
							waitingmsg += "The token symbol is then compared against CryptoCompare to get the latest value\n"
							waitingmsg += "Finally, CEB rates are used to convert USD -> SGD\n"
							waitingmsg += "That wasn't so hard, was it? Give this seal a hug! ◕ᴥ◕\n"
							waitingmsg += "If you have issues with the output contact @fatalityx to report bugs!"

							bot.sendMessage(chat_id=update.message.chat_id, text=waitingmsg,parse_mode='HTML')
							bot.send_chat_action(chat_id=update.message.chat_id, action=ChatAction.TYPING)
							ethplorerscan = Calculations().getalltokens(address)
							print(ethplorerscan)
							msg = Pmessage().pmsg(address,username,ethplorerscan)
							bot.sendMessage(chat_id=update.message.chat_id, text=msg,parse_mode='HTML')
					else:
						msg = "You are currently not registered! Please register with /register"
						bot.sendMessage(chat_id=update.message.chat_id, text=msg,parse_mode='HTML')
		except:
			catcherror = traceback.format_exc()
			bot.sendMessage(chat_id=channels.channellist('errorchannel'), text=str(catcherror),parse_mode='HTML')
Пример #7
0
	def wallet(bot,update):
		try:
			with closing(pymysql.connect(SQL.sqlinfo('host'),SQL.sqlinfo('usn'),SQL.sqlinfo('pw'),SQL.sqlinfo('db'),charset='utf8')) as conn:
				conn.autocommit(True)
				with closing(conn.cursor()) as cur:
					#gets wallet address
					wallet = update.message.text
					#retrieve user ID from telegram
					uid = update.message.from_user.id
					#runs check module (return True or False)
					check = web3check().web3check(wallet)
					#if invalid,
					if check is False:
						message = wallet
						message += " is not a valid Ethereum address!\n"
						message += "Please enter your wallet address again\n"
						message += "Your address should look something like this:\n"
						message += "0xCe9F2Bf18150f57512C2380231401dAF44A614e4\n"
						message += "<b>Be sure send me your address, not your private key!</b>"
						update.message.reply_text(message,parse_mode='HTML')
						#re-runs this process.
						return WALLET 
					#else, insert db
					else:
						cur.execute("""UPDATE mew SET mew_address = %s WHERE telegram_id = %s""",(wallet,uid,))
						cur.execute("""SELECT user_name FROM mew WHERE telegram_id = %s""",(uid,))
						if cur.rowcount > 0:
							data = cur.fetchone()
							name = data[0]
						else:
							name = "-"
						message = "Sucessfully binded "+wallet+" to "+name
						message += "\n"
						message += "You may now use /portfolio to generate a report."
						update.message.reply_text(message,parse_mode='HTML')
						#ends conversation state.
						return ConversationHandler.END 
		except:
			catcherror = traceback.format_exc()
			bot.sendMessage(chat_id=channels.channellist('errorchannel'), text=str(catcherror),parse_mode='HTML')
Пример #8
0
	def name (bot,update): #Enter name.
		try:
			with closing(pymysql.connect(SQL.sqlinfo('host'),SQL.sqlinfo('usn'),SQL.sqlinfo('pw'),SQL.sqlinfo('db'),charset='utf8')) as conn:
				conn.autocommit(True)
				with closing(conn.cursor()) as cur:
					name = update.message.text
					uid = update.message.from_user.id
					#check if name > 50 (DB Column set at 50 varchar.)
					if len(name) > 50: 
						message="Please send me a name that is under 50 characters"
						update.message.reply_text(message,parse_mode='HTML')
						#returns username state again.
						return USERNAME 
					#if name entered < 50, Insert DB, continue.
					else:
						cur.execute("""INSERT INTO mew VALUES(NULL,%s,%s,NULL)""",(name,uid,))
						message = "Can I have the address of your wallet?\n"
						message += "<b>Please send me your address, not your private key!</b>"
						update.message.reply_text(message,parse_mode='HTML')
						return WALLET #return wallet state, check hermes file.
		except:
			catcherror = traceback.format_exc()
			bot.sendMessage(chat_id=channels.channellist('errorchannel'), text=str(catcherror),parse_mode='HTML')
Пример #9
0
	def calculatekyber(bot,update):
		try:
			kyber = (update.message.text)[11:]
			if not kyber.strip():
				message = "The format for this command is /calckyber [float]KNC or /calckyber $[float] where float is a numerical value"
				bot.sendMessage(chat_id=update.message.chat_id, text=message,parse_mode='HTML')
			else:
				if (str(kyber[-3:])).lower() == "knc":
					try:
						float(kyber[:-3])
					except:
						message = "Please enter a numerical value !\n"
						message += "The bot accepts the following: /calckyber [float]KNC or /calckyber $[float]"
						bot.sendMessage(chat_id=update.message.chat_id, text=message,parse_mode='HTML')
					else:
						kyber = float(kyber[:-3])
						knclist = []
						knclist = knclist + (Liqui().knceth())
						knc = "<b>"+str(kyber)+" kyber tokens is worth ... </b>\n"
						knc += "<b>Based on 🚀Liqui, </b>"
						for each in knclist:
							if "kncbuysgd" in each:
								knc += "🇸🇬💸SGD Buy: $"
								knc += str(round((kyber * each["kncbuysgd"]),2))
								knc += "\n"
							elif "kncsellsgd" in each:
								knc += "🇸🇬💰SGD Sell: $"
								knc += str(round((kyber * each["kncsellsgd"]),2))
								knc += "\n"
							elif "kncbuyusd" in each:
								knc += "🇺🇸💸USD Buy: $"
								knc += str(round((kyber * each["kncbuyusd"]),2))
								knc += "\n"
							elif "kncsellusd" in each:
								knc += "🇺🇸💰USD Sell: $"
								knc += str(round((kyber * each["kncsellusd"]),2))
								knc += "\n"
						cryptocomparelist = []
						cryptocomparelist = cryptocomparelist + (Cryptocompare().geturl('KNC'))
						knc += "<b>Based on 💱CryptoCompare, </b>"
						for each in cryptocomparelist:
							if "sgd" in each:
								knc += "🇸🇬SGD Buy: $"
								knc += str(round((kyber * each["sgd"]),2))
								knc += "\n"
							elif "usd" in each:
								knc += "🇺🇸💸USD : $"
								knc += str(round((kyber * each["usd"]),2))
								knc += "\n"

						knc += "<i>** All values are rounded to 2 decimals</i>"
						bot.sendMessage(chat_id=update.message.chat_id, text=knc,parse_mode='HTML')
				else:
					#for fiat to knc, we're going to use the sell value.
					#this is because we're asumming that you're going to buy at their selling price.
					if kyber[:1] != "$":
						message = "Please enter a recognised input !\n"
						message += "The bot accepts the following: /calckyber [float]KNC or /calckyber $[float] where float is a numerical value"
						bot.sendMessage(chat_id=update.message.chat_id, text=message,parse_mode='HTML')
					else:
						try:
							float(kyber[1:])
							print(kyber[1:])
						except:
							message = "Please enter a numerical value !\n"
							message += "The bot accepts the following: /calckyber [float]KNC or /calckyber $[float] where float is a numerical value"
							bot.sendMessage(chat_id=update.message.chat_id, text=message,parse_mode='HTML')
						else:
							fiat = float(kyber[1:])
							knclist = []
							knclist = knclist + (Liqui().knceth())
							knc = "<b>Based on 🚀Liqui, $"+str(fiat)+" can buy... </b>\n"
							for each in knclist:
								if "kncsellsgd" in each:
									knc += "🇸🇬$"
									knc += str(fiat)
									knc += " can buy "
									knc += str(round(((1/each["kncsellsgd"])*fiat),2))
									knc += " kyber tokens\n"
								elif "kncsellusd" in each:
									knc += "🇺🇸$"
									knc += str(fiat)
									knc += " can buy "
									knc += str(round(((1/each["kncsellusd"])*fiat),2))
									knc += " kyber tokens\n"
							knc += "<i>** All values are rounded to 2 decimals</i>"
							bot.sendMessage(chat_id=update.message.chat_id, text=knc,parse_mode='HTML')
		except:
			catcherror = traceback.format_exc()
			bot.sendMessage(chat_id=channels.channellist('errorchannel'), text=str(catcherror),parse_mode='HTML')
Пример #10
0
	def calculateeth(bot,update):
		try:
			ether = (update.message.text)[9:]
			if not ether.strip():
				message = "The format for this command is /calceth [float]ETH or /calceth $[float] where float is a numerical value"
				bot.sendMessage(chat_id=update.message.chat_id, text=message,parse_mode='HTML')
			else:
				if (str(ether[-3:])).lower() == "eth":
					try:
						float(ether[:-3])
					except:
						message = "Please enter a numerical value !\n"
						message += "The bot accepts the following: /calceth [float]ETH or /calceth $[float] where float is a numerical value"
						bot.sendMessage(chat_id=update.message.chat_id, text=message,parse_mode='HTML')
					else:
						#for eth -> fiat, we're only going to use buy value
						#this is because we're asumming you'll sell at the buy price.
						ethereum = float(ether[:-3])
						eth = "<b>Based on 👛Cryptocompare, "+str(ethereum)+" ETH is worth ... </b>\n"
						ethlist = []
						ethlist = ethlist + (Cryptocompare().geturl('ETH'))
						for each in ethlist:
							if "sgd" in each:
								eth += "🇸🇬SGD** $"
								eth += str(round((ethereum * float(each["sgd"])),2))
								eth += "\n"
							elif "usd" in each:
								eth += "🇺🇸USD $"
								eth += str(round((ethereum * float(each["usd"])),2))
								eth += "\n"

						eth += "<i>* All values are rounded to 2 decimals</i>\n <i>**Calculated using CEB rates</i>"
						bot.sendMessage(chat_id=update.message.chat_id, text=eth,parse_mode='HTML')
				else:
					#for fiat -> eth, we're only going to use sell value
					#this is because we're asumming you'll buy at the sell price.
					if ether[:1] != "$":
						message = "Please enter a recognised input !\n"
						message += "The bot accepts the following: /calceth [float]ETH or /calceth $[float] where float is a numerical value"
						bot.sendMessage(chat_id=update.message.chat_id, text=message,parse_mode='HTML')
					else:
						try:
							float(ether[1:])
						except:
							message = "Please enter a numerical value !\n"
							message += "The bot accepts the following: /calceth [float]ETH or /calceth $[float] where float is a numerical value"
							bot.sendMessage(chat_id=update.message.chat_id, text=message,parse_mode='HTML')
						else:
							fiat = float(ether[1:])
							eth = "<b>Based on 👛Cryptocompare, $"+str(fiat)+" can buy ... </b>\n"
							ethlist = []
							ethlist = ethlist + (Cryptocompare().geturl('ETH'))
							for each in ethlist:
								if "sgd" in each:
									eth += "🇸🇬SGD** $"
									eth += str(fiat)
									eth += " can buy "
									eth += str(round(((1/float(each["sgd"]))*fiat),2))
									eth += " ETH\n"
								elif "usd" in each:
									eth += "🇺🇸USD $"
									eth += str(fiat)
									eth += " can buy "
									eth += str(round(((1/float(each["usd"]))*fiat),2))
									eth += " ETH\n"

							eth += "<i>** All values are rounded to 2 decimals</i>\n <i>**Calculated using CEB rates</i>"
							bot.sendMessage(chat_id=update.message.chat_id, text=eth,parse_mode='HTML')



		except:
			catcherror = traceback.format_exc()
			bot.sendMessage(chat_id=channels.channellist('errorchannel'), text=str(catcherror),parse_mode='HTML')