From 55d54389c46a8fbf76666a48f558fbea185e21e7 Mon Sep 17 00:00:00 2001 From: acidvegas Date: Sat, 21 Mar 2020 03:14:11 -0400 Subject: [PATCH] Added double fees loop, removed all 3rd party library requirements, cleaned up --- README.md | 3 +- irccex/core/{cmc.py => coinmarketcap.py} | 29 ++++++++------- irccex/core/config.py | 1 - irccex/core/irc.py | 45 +++++++++++++++++------- irccex/data/cert/.gitignore | 4 --- irccex/data/dbx.py | 12 ------- irccex/data/logs/.gitignore | 4 --- 7 files changed, 48 insertions(+), 50 deletions(-) rename irccex/core/{cmc.py => coinmarketcap.py} (63%) delete mode 100644 irccex/data/cert/.gitignore delete mode 100644 irccex/data/dbx.py delete mode 100644 irccex/data/logs/.gitignore diff --git a/README.md b/README.md index 49e4cc3..788783c 100644 --- a/README.md +++ b/README.md @@ -83,15 +83,16 @@ Support the project development if you like it: [Patreon.com/irccex](https://pat The IRCCEX project is completely open source & non-profit, though any support/pledges will help in motivation towards more development and adding new features! ###### Future Concepts & Ideas +* Use multiple API keys to prevent rate limiting. * IRCCEX BlockChain - Keep an on-going ledger of every single transaction ever made in the channel. *(No idea what use it would have. Maybe a `!trades` command for recent history. The idea makes me laugh)* * Buying options - Spend a large sum of money on features like locking someone from trading for X amount of time (Charge Y per hour and max it to 24 hours), wallet spying, wallet bombing (sending a bunch of shitcoins), hindsight where you get private message alerts on a coins price changing (can be used whenever only once). -* Double fees for 1-3 days randomly in round! * Post reward pool bangs will make you lose money to fuck with people spamming hard with bots to rack up the pool * Crate Drops - A "crate" will drop randomly in the channel that requires multiple `!break`'s to open it. Once opened, there will be 4 items you can get by typing the ! command under it. Items will include money, extra privlegges like holding more coins, and other items you can win. * **Suicide Round** - There is no bank in this mode, and if you lose your nick through a NICK or QUIT, you lose your wallet. Round can last 3-7 days and the top 10 wallets will score. * **Bank Round** - Round lasts a week and the top 10 players in the bank will score. * **Flash Match** - Round lasts a day and the top 10 players in the bank will score. +###### Try it out We are running IRCCEX actively in **#exchange** on **EFNet** & **SuperNETs**, come chat with us, make some money, and share ideas! ###### Mirrors diff --git a/irccex/core/cmc.py b/irccex/core/coinmarketcap.py similarity index 63% rename from irccex/core/cmc.py rename to irccex/core/coinmarketcap.py index 7a2a2d9..3d2cfe3 100644 --- a/irccex/core/cmc.py +++ b/irccex/core/coinmarketcap.py @@ -1,24 +1,23 @@ #!/usr/bin/env python -# IRC Cryptocurrency Exchange (IRCCEX) - Developed by acidvegas in Python (https://acid.vegas/irccex) -# cmc.py +# CoinMarketCap API Class - Developed by acidvegas in Python (https://acid.vegas/coinmarketcap) +import http.client import json import time - -import requests - -import config +import zlib class CoinMarketCap(object): - def __init__(self): - self.cache = {'global':dict(), 'ticker':dict()} - self.last = {'global':0 , 'ticker':0 } + def __init__(self, api_key): + self.api_key = api_key + self.cache = {'global':dict(), 'ticker':dict()} + self.last = {'global':0 , 'ticker':0 } - def _api(self, _endpoint, _params={}): - session = requests.Session() - session.headers.update({'Accept':'application/json', 'Accept-Encoding':'deflate, gzip', 'X-CMC_PRO_API_KEY':config.CMC_API_KEY}) - response = session.get('https://pro-api.coinmarketcap.com/v1/' + _endpoint, params=_params, timeout=15) - return json.loads(response.text.replace(': null', ': "0"'))['data'] + def _api(self, _endpoint): + conn = http.client.HTTPSConnection('pro-api.coinmarketcap.com', timeout=15) + conn.request('GET', '/v1/' + _endpoint, headers={'Accept':'application/json', 'Accept-Encoding':'deflate, gzip', 'X-CMC_PRO_API_KEY':self.api_key}) + response = zlib.decompress(conn.getresponse().read(), 16+zlib.MAX_WBITS).decode('utf-8').replace(': null', ': "0"') + conn.close() + return json.loads(response)['data'] def _global(self): if time.time() - self.last['global'] < 300: @@ -40,7 +39,7 @@ class CoinMarketCap(object): if time.time() - self.last['ticker'] < 300: return self.cache['ticker'] else: - data = self._api('cryptocurrency/listings/latest', {'limit':'5000'}) + data = self._api('cryptocurrency/listings/latest?limit=5000') self.cache['ticker'] = dict() for item in data: self.cache['ticker'][item['symbol']] = { diff --git a/irccex/core/config.py b/irccex/core/config.py index 81e4b3c..f1c56e3 100644 --- a/irccex/core/config.py +++ b/irccex/core/config.py @@ -15,7 +15,6 @@ class connection: class cert: key = None - file = None password = None class ident: diff --git a/irccex/core/irc.py b/irccex/core/irc.py index 09d5ea8..c5b3491 100644 --- a/irccex/core/irc.py +++ b/irccex/core/irc.py @@ -20,7 +20,7 @@ import time import config import constants import functions -from cmc import CoinMarketCap +from coinmarketcap import CoinMarketCap if config.connection.ssl: import ssl @@ -43,8 +43,8 @@ class IRC(object): self.start = time.time() def run(self): - if os.path.isfile('data/db.pkl'): - with open('data/db.pkl', 'rb') as db_file: + if os.path.isfile('db.pkl'): + with open('db.pkl', 'rb') as db_file: self.db = pickle.load(db_file) print('[+] - Restored database!') Loops.start_loops() @@ -62,21 +62,19 @@ class IRC(object): self.listen() def create_socket(self): - family = socket.AF_INET6 if config.connection.ipv6 else socket.AF_INET - self.sock = socket.socket(family, socket.SOCK_STREAM) + self.sock = socket.socket(AF_INET6) if config.connection.ipv6 else socket.socket() if config.connection.vhost: self.sock.bind((config.connection.vhost, 0)) if config.connection.ssl: ctx = ssl.SSLContext() if config.cert.file: - ctx.load_cert_chain(config.cert.file, config.cert.key, config.cert.password) + ctx.load_cert_chain(config.cert.file, password=config.cert.password) if config.connection.ssl_verify: - ctx.verify_mode = ssl.CERT_REQUIRED + ctx.check_hostname = True ctx.load_default_certs() + self.sock = ctx.wrap_socket(self.sock, server_hostname=config.connection.server) else: - ctx.check_hostname = False - ctx.verify_mode = ssl.CERT_NONE - self.sock = ctx.wrap_socket(self.sock) + self.sock = ctx.wrap_socket(self.sock) def listen(self): while True: @@ -204,7 +202,7 @@ class Events: Commands.sendmsg(chan, 'Cashed out {0} to your bank account! {1}'.format(color('${:,}'.format(int(amount)), constants.green), color('(current balance: ${:,})'.format(int(Bot.db['bank'][nick][0])), constants.grey))) elif len(args) == 1: if msg == '@irccex': - Commands.sendmsg(chan, constants.bold + 'IRC Cryptocurrency Exchange (IRCCEX) - Developed by acidvegas in Python - https://acid.vegas/irccex') + Commands.sendmsg(chan, constants.bold + 'IRC Cryptocurrency Exchange (IRCCEX) - Developed by acidvegas in Python - https://github.com/acidvegas/irccex') elif msg == '@stats': bank_total = 0 global_data = CMC._global() @@ -501,6 +499,7 @@ class Events: class Loops: def start_loops(): threading.Thread(target=Loops.backup).start() + threading.Thread(target=Loops.double_fees).start() threading.Thread(target=Loops.maintenance).start() threading.Thread(target=Loops.remind).start() threading.Thread(target=Loops.reward).start() @@ -510,11 +509,31 @@ class Loops: def backup(): while True: time.sleep(3600) # 1H - with open('data/db.pkl', 'wb') as db_file: + with open('db.pkl', 'wb') as db_file: pickle.dump(Bot.db, db_file, pickle.HIGHEST_PROTOCOL) Bot.last_backup = time.strftime('%I:%M') print('[+] - Database backed up!') + def double_fees(): + original_fees = {'cashout':config.fees.cashout,'send':config.fees.send,'trade':config.fees.trade} + while True: + try: + time.sleep(functions.random_int(604800,864000)) # 7D - 10D + config.fees.cashout = original_fees['cashout']*2 + config.fees.send = original_fees['send']*2 + config.fees.trade = original_fees['trade']*2 + Commands.action(config.connection.channel, color('Double fees have been activated!', constants.red)) + time.sleep(functions.random_int(86400, 259200)) # 1D - 3D + config.fees.cashout = original_fees['cashout']/2 + config.fees.send = original_fees['send']/2 + config.fees.trade = original_fees['trade']/2 + Commands.notice(config.connection.channel, color('Double fees have been deactivated!', constants.red)) + except Exception as ex: + config.fees.cashout = original_fees['cashout'] + config.fees.send = original_fees['send'] + config.fees.trade = original_fees['trade'] + print('[!] - Error occured in the double fees loop! (' + str(ex) + ')') + def maintenance(): while True: try: @@ -596,5 +615,5 @@ class Loops: finally: time.sleep(3600) # 1H -CMC = CoinMarketCap() Bot = IRC() +CMC = CoinMarketCap(config.CMC_API_KEY) \ No newline at end of file diff --git a/irccex/data/cert/.gitignore b/irccex/data/cert/.gitignore deleted file mode 100644 index 86d0cb2..0000000 --- a/irccex/data/cert/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore \ No newline at end of file diff --git a/irccex/data/dbx.py b/irccex/data/dbx.py deleted file mode 100644 index 066067b..0000000 --- a/irccex/data/dbx.py +++ /dev/null @@ -1,12 +0,0 @@ -import pickle, coinmarketcap -CMC = coinmarketcap.CoinMarketCap() -DB = pickle.load(open('db.pkl' 'rb')) -wallets = dict() -for nick in DB['wallet']: - total = 0 - for symbol in DB['wallet'][nick]: - total += DB['wallet'][nick][symbol] if symbol == 'USD' else CMC.get()[symbol]['price_usd']*DB['wallet'][nick][symbol] - wallets[nick] = total -data = sorted(wallets, key=wallets.get, reverse=True) -for item in data: - print('[{0:02}] {1} ${2:,}'.format(data.index(item)+1, item.ljust(9), wallets[item])) diff --git a/irccex/data/logs/.gitignore b/irccex/data/logs/.gitignore deleted file mode 100644 index 86d0cb2..0000000 --- a/irccex/data/logs/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore \ No newline at end of file