Added double fees loop, removed all 3rd party library requirements, cleaned up

This commit is contained in:
Dionysus 2020-03-21 03:14:11 -04:00
parent 54783c8b7c
commit 55d54389c4
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE
7 changed files with 48 additions and 50 deletions

View File

@ -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! 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 ###### 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)* * 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). * 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 * 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. * 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. * **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. * **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. * **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! We are running IRCCEX actively in **#exchange** on **EFNet** & **SuperNETs**, come chat with us, make some money, and share ideas!
###### Mirrors ###### Mirrors

View File

@ -1,24 +1,23 @@
#!/usr/bin/env python #!/usr/bin/env python
# IRC Cryptocurrency Exchange (IRCCEX) - Developed by acidvegas in Python (https://acid.vegas/irccex) # CoinMarketCap API Class - Developed by acidvegas in Python (https://acid.vegas/coinmarketcap)
# cmc.py
import http.client
import json import json
import time import time
import zlib
import requests
import config
class CoinMarketCap(object): class CoinMarketCap(object):
def __init__(self): def __init__(self, api_key):
self.api_key = api_key
self.cache = {'global':dict(), 'ticker':dict()} self.cache = {'global':dict(), 'ticker':dict()}
self.last = {'global':0 , 'ticker':0 } self.last = {'global':0 , 'ticker':0 }
def _api(self, _endpoint, _params={}): def _api(self, _endpoint):
session = requests.Session() conn = http.client.HTTPSConnection('pro-api.coinmarketcap.com', timeout=15)
session.headers.update({'Accept':'application/json', 'Accept-Encoding':'deflate, gzip', 'X-CMC_PRO_API_KEY':config.CMC_API_KEY}) conn.request('GET', '/v1/' + _endpoint, headers={'Accept':'application/json', 'Accept-Encoding':'deflate, gzip', 'X-CMC_PRO_API_KEY':self.api_key})
response = session.get('https://pro-api.coinmarketcap.com/v1/' + _endpoint, params=_params, timeout=15) response = zlib.decompress(conn.getresponse().read(), 16+zlib.MAX_WBITS).decode('utf-8').replace(': null', ': "0"')
return json.loads(response.text.replace(': null', ': "0"'))['data'] conn.close()
return json.loads(response)['data']
def _global(self): def _global(self):
if time.time() - self.last['global'] < 300: if time.time() - self.last['global'] < 300:
@ -40,7 +39,7 @@ class CoinMarketCap(object):
if time.time() - self.last['ticker'] < 300: if time.time() - self.last['ticker'] < 300:
return self.cache['ticker'] return self.cache['ticker']
else: else:
data = self._api('cryptocurrency/listings/latest', {'limit':'5000'}) data = self._api('cryptocurrency/listings/latest?limit=5000')
self.cache['ticker'] = dict() self.cache['ticker'] = dict()
for item in data: for item in data:
self.cache['ticker'][item['symbol']] = { self.cache['ticker'][item['symbol']] = {

View File

@ -15,7 +15,6 @@ class connection:
class cert: class cert:
key = None key = None
file = None
password = None password = None
class ident: class ident:

View File

@ -20,7 +20,7 @@ import time
import config import config
import constants import constants
import functions import functions
from cmc import CoinMarketCap from coinmarketcap import CoinMarketCap
if config.connection.ssl: if config.connection.ssl:
import ssl import ssl
@ -43,8 +43,8 @@ class IRC(object):
self.start = time.time() self.start = time.time()
def run(self): def run(self):
if os.path.isfile('data/db.pkl'): if os.path.isfile('db.pkl'):
with open('data/db.pkl', 'rb') as db_file: with open('db.pkl', 'rb') as db_file:
self.db = pickle.load(db_file) self.db = pickle.load(db_file)
print('[+] - Restored database!') print('[+] - Restored database!')
Loops.start_loops() Loops.start_loops()
@ -62,20 +62,18 @@ class IRC(object):
self.listen() self.listen()
def create_socket(self): def create_socket(self):
family = socket.AF_INET6 if config.connection.ipv6 else socket.AF_INET self.sock = socket.socket(AF_INET6) if config.connection.ipv6 else socket.socket()
self.sock = socket.socket(family, socket.SOCK_STREAM)
if config.connection.vhost: if config.connection.vhost:
self.sock.bind((config.connection.vhost, 0)) self.sock.bind((config.connection.vhost, 0))
if config.connection.ssl: if config.connection.ssl:
ctx = ssl.SSLContext() ctx = ssl.SSLContext()
if config.cert.file: 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: if config.connection.ssl_verify:
ctx.verify_mode = ssl.CERT_REQUIRED ctx.check_hostname = True
ctx.load_default_certs() ctx.load_default_certs()
self.sock = ctx.wrap_socket(self.sock, server_hostname=config.connection.server)
else: 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): def listen(self):
@ -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))) 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: elif len(args) == 1:
if msg == '@irccex': 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': elif msg == '@stats':
bank_total = 0 bank_total = 0
global_data = CMC._global() global_data = CMC._global()
@ -501,6 +499,7 @@ class Events:
class Loops: class Loops:
def start_loops(): def start_loops():
threading.Thread(target=Loops.backup).start() threading.Thread(target=Loops.backup).start()
threading.Thread(target=Loops.double_fees).start()
threading.Thread(target=Loops.maintenance).start() threading.Thread(target=Loops.maintenance).start()
threading.Thread(target=Loops.remind).start() threading.Thread(target=Loops.remind).start()
threading.Thread(target=Loops.reward).start() threading.Thread(target=Loops.reward).start()
@ -510,11 +509,31 @@ class Loops:
def backup(): def backup():
while True: while True:
time.sleep(3600) # 1H 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) pickle.dump(Bot.db, db_file, pickle.HIGHEST_PROTOCOL)
Bot.last_backup = time.strftime('%I:%M') Bot.last_backup = time.strftime('%I:%M')
print('[+] - Database backed up!') 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(): def maintenance():
while True: while True:
try: try:
@ -596,5 +615,5 @@ class Loops:
finally: finally:
time.sleep(3600) # 1H time.sleep(3600) # 1H
CMC = CoinMarketCap()
Bot = IRC() Bot = IRC()
CMC = CoinMarketCap(config.CMC_API_KEY)

View File

@ -1,4 +0,0 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

View File

@ -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]))

View File

@ -1,4 +0,0 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore