Added double fees loop, removed all 3rd party library requirements, cleaned up
This commit is contained in:
parent
54783c8b7c
commit
55d54389c4
@ -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
|
||||
|
@ -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']] = {
|
@ -15,7 +15,6 @@ class connection:
|
||||
|
||||
class cert:
|
||||
key = None
|
||||
file = None
|
||||
password = None
|
||||
|
||||
class ident:
|
||||
|
@ -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)
|
4
irccex/data/cert/.gitignore
vendored
4
irccex/data/cert/.gitignore
vendored
@ -1,4 +0,0 @@
|
||||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
@ -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]))
|
4
irccex/data/logs/.gitignore
vendored
4
irccex/data/logs/.gitignore
vendored
@ -1,4 +0,0 @@
|
||||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
Loading…
Reference in New Issue
Block a user