Initial commit

This commit is contained in:
Dionysus 2020-02-21 22:10:37 -05:00
commit 54783c8b7c
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE
12 changed files with 1207 additions and 0 deletions

15
LICENSE Normal file
View File

@ -0,0 +1,15 @@
ISC License
Copyright (c) 2020, acidvegas <acid.vegas@acid.vegas>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

100
README.md Normal file
View File

@ -0,0 +1,100 @@
# irccex
A fantasy cryptocurrency exchange for the Internet Relay Chat (IRC) protocol.
*"You can pretend trade currencies, instead of trade pretend currencies!"* ~ some guy on reddit
*"this bot is begging to be used for not playing"* ~ yuritrue
*"its a game, trade hard & get rich or die tryin`"* ~ contra
###### Requirments
* [Python](https://www.python.org/downloads/) *(**Note:** This script was developed to be used with the latest version of Python.)*
###### Information
This bot lets users of an IRC channel "pretend" trade cryptocurrencies in a competitive round-based game manner. Real time market data from [CoinMarketCap](https://coinmarketcap.com/) is used to obtain the values and other information of the cryptocurrencies traded.
Users can make an exchange account with the `!register` command, and after 24 hours, are given `init_funds` to start trading with. There is no authentication required for interacting with exchange accounts. Everything is regulated based on the nick of whoever issues a command. Users can `/nick` to any nick with an account to access it. This means it is possible to steal cryptocurrency using the `!send` command.
Bank accounts can be added to with the `!cashout` command, which deposits all of your USD profits from your wallet. Once money is in the bank, it can not be withdrawn. Maintaining your nick and doing frequent cashouts to your bank is the only way to protect your money. The goal is to have the largest bank account by the end of the round.
Every round starts a new "game mode", which affects how the round will end or how the scoring is done for the winner(s). The main goal of the entire game is to collect points from winning game rounds, which can be seen using the `!scores` command.
###### Strategy
There are many ways to become skilled in this game. Making *legit* trades that you would do in the market with real money is the last fucking on that list.
I know what you're thinking... "Can't I just register 500 accounts & have them all !trade and !send money and get RICH?" Yes, you can do that! But just know you are not going to be the first or the last to ever think of that.
This game can introduce lots of trolling & botting. Get creative & figure out ways to make money, secure money, steal money, and more!
###### Loops
* The database will backup to a pickle file every hour. The last backup time can be seen in the `@stats` reply. Make note of this before restarting the bot for some reason.
* The exchange will random enter "maintenance mode" once every 3 days, which locks the use of all exchange commands. Maintenance can last an hour to a full day.
* All fees are collected & stored in the "reward pool". The bot will make an announcement randomly before the round ends & anyone who types `!bang` after that will get a reward taken from the pool. It takes 25 to 50 `!bang`'s to completely empty the pool. The final person to `!bang` will get the largest reward.
###### Trading Pair Rules
- USD can only be used for buying or selling BTC, ETH, & LTC.
- BTC & ETH are the only major trading pairs between all other cryptocurrencies.
###### Fees & Minimums
| Command | Fee | Minimum |
| --- | --- | --- |
| cashout | 2% | $10000 USD Balance |
| send | 1% | $5000 Balance |
| trade | 0.1% | $5 |
###### Exchange Commands
| Command | Description |
| --- | --- |
| @irccex | Information about the bot. |
| @stats | Statistics on the exchange, market, and more. |
| $\<symbol> | Return information for the \<symbol> cryptocurrency. *(\<symbol> can also be a comma seperated list)* |
| !bang | Grab a reward when the reward pool is triggered. |
| !bank | Return your total bank account balance. |
| !bottom \<1h/24h/7d/value/volume> | Return information for the bottom 10 cryptocurrencies based on the \<1h/24h/7d/value>. |
| !cashout [msg] | Deposit all your USD to your bank account and optionally leave the [msg] message for the !rich list. |
| !portfolio | Total USD value of your wallet. |
| !register | Register an exchange account. |
| !rich | Return the top 10 richest bank accounts. |
| !score | Return your score & rank on the leaderboard. |
| !scores | Return the top 10 players on the leaderboard. |
| !send \<nick> \<amount> \<symbol> | Send \<amount> of \<symbol> to \<nick>. |
| !top [\<1h/24h/7d/value/volume>] | Return information for the top 10 cryptocurrencies, optionally based on \<1h/24h/7d/value/volume>. |
| !trade \<pair> \<amount> | Trade \<amount> between \<pair>. |
| !value \<amount> \<name> | Convert \<amount> of the \<name> cryptocurrency to it's value. |
| !wallet | View your exchange wallet. |
- \<amount> can be the symbols amount, USD amount if prefixed with a $, or the total amount you hold if * is used.
* `!send acidvegas 0.05 BTC` sends 0.05 BTC to acidvegas.
* `!send chrono $10.00 BTC` sends $10.00 worth of BTC to chrono.
* `!send mikejonez * BTC` sends all of your BTC to mikejonez.
* `!send vap0r 1,000,000 USD` commas can also be used in the amount.
- \<pair> is the from_symbol/to_symbol you are wanting to make trades with.
* `!trade ETH/NANO 0.14` trades 0.14 ETH to NANO.
* `!trade XRP/BTC $100` trades $100 USD worth of XRP to BTC.
* `!trade ETH/DOGE *` trades all of your ETH to DOGE.
###### Patreons
Support the project development if you like it: [Patreon.com/irccex](https://patreon.com/irccex)
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
* 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.
We are running IRCCEX actively in **#exchange** on **EFNet** & **SuperNETs**, come chat with us, make some money, and share ideas!
###### Mirrors
- [acid.vegas](https://acid.vegas/irccex) *(main)*
- [GitHub](https://github.com/acidvegas/irccex)
- [GitLab](https://gitlab.com/acidvegas/irccex)

1
funding.yml Normal file
View File

@ -0,0 +1 @@
patreon: irccex

56
irccex/core/cmc.py Normal file
View File

@ -0,0 +1,56 @@
#!/usr/bin/env python
# IRC Cryptocurrency Exchange (IRCCEX) - Developed by acidvegas in Python (https://acid.vegas/irccex)
# cmc.py
import json
import time
import requests
import config
class CoinMarketCap(object):
def __init__(self):
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 _global(self):
if time.time() - self.last['global'] < 300:
return self.cache['global']
else:
data = self._api('global-metrics/quotes/latest')
self.cache['global'] = {
'cryptocurrencies' : data['active_cryptocurrencies'],
'exchanges' : data['active_exchanges'],
'btc_dominance' : int(data['btc_dominance']),
'eth_dominance' : int(data['eth_dominance']),
'market_cap' : int(data['quote']['USD']['total_market_cap']),
'volume' : int(data['quote']['USD']['total_volume_24h'])
}
self.last['global'] = time.time()
return self.cache['global']
def _ticker(self):
if time.time() - self.last['ticker'] < 300:
return self.cache['ticker']
else:
data = self._api('cryptocurrency/listings/latest', {'limit':'5000'})
self.cache['ticker'] = dict()
for item in data:
self.cache['ticker'][item['symbol']] = {
'name' : item['name'],
'symbol' : item['symbol'],
'rank' : item['cmc_rank'],
'price' : float(item['quote']['USD']['price']),
'percent' : {'1h':float(item['quote']['USD']['percent_change_1h']), '24h':float(item['quote']['USD']['percent_change_24h']), '7d':float(item['quote']['USD']['percent_change_7d'])},
'volume' : int(float(item['quote']['USD']['volume_24h'])),
'market_cap' : int(float(item['quote']['USD']['market_cap']))
}
self.last['ticker'] = time.time()
return self.cache['ticker']

49
irccex/core/config.py Normal file
View File

@ -0,0 +1,49 @@
#!/usr/bin/env python
# IRC Cryptocurrency Exchange (IRCCEX) - Developed by acidvegas in Python (https://acid.vegas/irccex)
# config.py
class connection:
server = 'irc.server.com'
port = 6667
ipv6 = False
ssl = False
ssl_verify = False
vhost = None
channel = '#exchange'
key = None
modes = None
class cert:
key = None
file = None
password = None
class ident:
nickname = 'IRCCEX'
username = 'exchange'
realname = 'acid.vegas/irccex'
class login:
network = None
nickserv = None
operator = None
class throttle:
cmd = 3
msg = 0.5
reconnect = 10
rejoin = 3
class limits:
assets = 10 # Maximum number of assets held
cashout = 5000 # Minimum USD required to !cashout
init = 1000 # Initial USD for people who !register
send = 2500 # Minimum balance required for !send
trade = 5 # Minimum USD amount for !trade
class fees:
cashout = 0.02 # 2%
send = 0.01 # 1%
trade = 0.001 # 0.1%
CMC_API_KEY = 'CHANGEME' # https://pro.coinmarketcap.com/signup

213
irccex/core/constants.py Normal file
View File

@ -0,0 +1,213 @@
#!/usr/bin/env python
# IRC Cryptocurrency Exchange (IRCCEX) - Developed by acidvegas in Python (https://acid.vegas/irccex)
# constants.py
# Control Characters
bold = '\x02'
color = '\x03'
italic = '\x1D'
underline = '\x1F'
reverse = '\x16'
reset = '\x0f'
# Color Codes
white = '00'
black = '01'
blue = '02'
green = '03'
red = '04'
brown = '05'
purple = '06'
orange = '07'
yellow = '08'
light_green = '09'
cyan = '10'
light_cyan = '11'
light_blue = '12'
pink = '13'
grey = '14'
light_grey = '15'
# Events
PASS = 'PASS'
NICK = 'NICK'
USER = 'USER'
OPER = 'OPER'
MODE = 'MODE'
SERVICE = 'SERVICE'
QUIT = 'QUIT'
SQUIT = 'SQUIT'
JOIN = 'JOIN'
PART = 'PART'
TOPIC = 'TOPIC'
NAMES = 'NAMES'
LIST = 'LIST'
INVITE = 'INVITE'
KICK = 'KICK'
PRIVMSG = 'PRIVMSG'
NOTICE = 'NOTICE'
MOTD = 'MOTD'
LUSERS = 'LUSERS'
VERSION = 'VERSION'
STATS = 'STATS'
LINKS = 'LINKS'
TIME = 'TIME'
CONNECT = 'CONNECT'
TRACE = 'TRACE'
ADMIN = 'ADMIN'
INFO = 'INFO'
SERVLIST = 'SERVLIST'
SQUERY = 'SQUERY'
WHO = 'WHO'
WHOIS = 'WHOIS'
WHOWAS = 'WHOWAS'
KILL = 'KILL'
PING = 'PING'
PONG = 'PONG'
ERROR = 'ERROR'
AWAY = 'AWAY'
REHASH = 'REHASH'
DIE = 'DIE'
RESTART = 'RESTART'
SUMMON = 'SUMMON'
USERS = 'USERS'
WALLOPS = 'WALLOPS'
USERHOST = 'USERHOST'
ISON = 'ISON'
# Event Numerics
RPL_WELCOME = '001'
RPL_YOURHOST = '002'
RPL_CREATED = '003'
RPL_MYINFO = '004'
RPL_ISUPPORT = '005'
RPL_TRACELINK = '200'
RPL_TRACECONNECTING = '201'
RPL_TRACEHANDSHAKE = '202'
RPL_TRACEUNKNOWN = '203'
RPL_TRACEOPERATOR = '204'
RPL_TRACEUSER = '205'
RPL_TRACESERVER = '206'
RPL_TRACESERVICE = '207'
RPL_TRACENEWTYPE = '208'
RPL_TRACECLASS = '209'
RPL_STATSLINKINFO = '211'
RPL_STATSCOMMANDS = '212'
RPL_STATSCLINE = '213'
RPL_STATSILINE = '215'
RPL_STATSKLINE = '216'
RPL_STATSYLINE = '218'
RPL_ENDOFSTATS = '219'
RPL_UMODEIS = '221'
RPL_SERVLIST = '234'
RPL_SERVLISTEND = '235'
RPL_STATSLLINE = '241'
RPL_STATSUPTIME = '242'
RPL_STATSOLINE = '243'
RPL_STATSHLINE = '244'
RPL_LUSERCLIENT = '251'
RPL_LUSEROP = '252'
RPL_LUSERUNKNOWN = '253'
RPL_LUSERCHANNELS = '254'
RPL_LUSERME = '255'
RPL_ADMINME = '256'
RPL_ADMINLOC1 = '257'
RPL_ADMINLOC2 = '258'
RPL_ADMINEMAIL = '259'
RPL_TRACELOG = '261'
RPL_TRYAGAIN = '263'
RPL_NONE = '300'
RPL_AWAY = '301'
RPL_USERHOST = '302'
RPL_ISON = '303'
RPL_UNAWAY = '305'
RPL_NOWAWAY = '306'
RPL_WHOISUSER = '311'
RPL_WHOISSERVER = '312'
RPL_WHOISOPERATOR = '313'
RPL_WHOWASUSER = '314'
RPL_ENDOFWHO = '315'
RPL_WHOISIDLE = '317'
RPL_ENDOFWHOIS = '318'
RPL_WHOISCHANNELS = '319'
RPL_LIST = '322'
RPL_LISTEND = '323'
RPL_CHANNELMODEIS = '324'
RPL_NOTOPIC = '331'
RPL_TOPIC = '332'
RPL_INVITING = '341'
RPL_INVITELIST = '346'
RPL_ENDOFINVITELIST = '347'
RPL_EXCEPTLIST = '348'
RPL_ENDOFEXCEPTLIST = '349'
RPL_VERSION = '351'
RPL_WHOREPLY = '352'
RPL_NAMREPLY = '353'
RPL_LINKS = '364'
RPL_ENDOFLINKS = '365'
RPL_ENDOFNAMES = '366'
RPL_BANLIST = '367'
RPL_ENDOFBANLIST = '368'
RPL_ENDOFWHOWAS = '369'
RPL_INFO = '371'
RPL_MOTD = '372'
RPL_ENDOFINFO = '374'
RPL_MOTDSTART = '375'
RPL_ENDOFMOTD = '376'
RPL_YOUREOPER = '381'
RPL_REHASHING = '382'
RPL_YOURESERVICE = '383'
RPL_TIME = '391'
RPL_USERSSTART = '392'
RPL_USERS = '393'
RPL_ENDOFUSERS = '394'
RPL_NOUSERS = '395'
ERR_NOSUCHNICK = '401'
ERR_NOSUCHSERVER = '402'
ERR_NOSUCHCHANNEL = '403'
ERR_CANNOTSENDTOCHAN = '404'
ERR_TOOMANYCHANNELS = '405'
ERR_WASNOSUCHNICK = '406'
ERR_TOOMANYTARGETS = '407'
ERR_NOSUCHSERVICE = '408'
ERR_NOORIGIN = '409'
ERR_NORECIPIENT = '411'
ERR_NOTEXTTOSEND = '412'
ERR_NOTOPLEVEL = '413'
ERR_WILDTOPLEVEL = '414'
ERR_BADMASK = '415'
ERR_UNKNOWNCOMMAND = '421'
ERR_NOMOTD = '422'
ERR_NOADMININFO = '423'
ERR_FILEERROR = '424'
ERR_NONICKNAMEGIVEN = '431'
ERR_ERRONEUSNICKNAME = '432'
ERR_NICKNAMEINUSE = '433'
ERR_NICKCOLLISION = '436'
ERR_USERNOTINCHANNEL = '441'
ERR_NOTONCHANNEL = '442'
ERR_USERONCHANNEL = '443'
ERR_NOLOGIN = '444'
ERR_SUMMONDISABLED = '445'
ERR_USERSDISABLED = '446'
ERR_NOTREGISTERED = '451'
ERR_NEEDMOREPARAMS = '461'
ERR_ALREADYREGISTRED = '462'
ERR_NOPERMFORHOST = '463'
ERR_PASSWDMISMATCH = '464'
ERR_YOUREBANNEDCREEP = '465'
ERR_KEYSET = '467'
ERR_CHANNELISFULL = '471'
ERR_UNKNOWNMODE = '472'
ERR_INVITEONLYCHAN = '473'
ERR_BANNEDFROMCHAN = '474'
ERR_BADCHANNELKEY = '475'
ERR_BADCHANMASK = '476'
ERR_BANLISTFULL = '478'
ERR_NOPRIVILEGES = '481'
ERR_CHANOPRIVSNEEDED = '482'
ERR_CANTKILLSERVER = '483'
ERR_UNIQOPRIVSNEEDED = '485'
ERR_NOOPERHOST = '491'
ERR_UMODEUNKNOWNFLAG = '501'
ERR_USERSDONTMATCH = '502'

133
irccex/core/functions.py Normal file
View File

@ -0,0 +1,133 @@
#!/usr/bin/env python
# IRC Cryptocurrency Exchange (IRCCEX) - Developed by acidvegas in Python (https://acid.vegas/irccex)
# functions.py
import calendar
import datetime
import random
import time
import constants
def check_pair(from_symbol, to_symbol):
if from_symbol == 'USD':
return True if to_symbol in ('BTC','ETH','LTC') else False
elif to_symbol == 'USD':
return True if from_symbol in ('BTC','ETH','LTC') else False
elif from_symbol == to_symbol:
return False
elif from_symbol in ('BTC','ETH') or to_symbol in ('BTC','ETH'):
return True
else:
return False
def clean_float(value):
if value > 24.99:
return int(value)
elif 'e-' in str(value):
return '{0:.8f}'.format(float(value))
else:
return '{0:.8g}'.format(float(value))
def clean_value(value):
value = float(value)
if value < 0.01:
return '${0:,.8f}'.format(value)
elif value < 24.99:
return '${0:,.2f}'.format(value)
else:
return '${:,}'.format(int(value))
def coin_info(data):
sep = color('|', constants.grey)
sep2 = color('/', constants.grey)
rank = color(data['rank'], constants.pink)
name = '{0} ({1})'.format(color(data['name'], constants.white), data['symbol'])
value = clean_value(data['price'])
perc_1h = color('{:,.2f}%'.format(data['percent']['1h']), percent_color(data['percent']['1h']))
perc_24h = color('{:,.2f}%'.format(data['percent']['24h']), percent_color(data['percent']['24h']))
perc_7d = color('{:,.2f}%'.format(data['percent']['7d']), percent_color(data['percent']['7d']))
percent = sep2.join((perc_1h,perc_24h,perc_7d))
volume = '{0} {1}'.format(color('Volume:', constants.white), '${:,}'.format(data['volume']))
cap = '{0} {1}'.format(color('Market Cap:', constants.white), '${:,}'.format(data['market_cap']))
return f'[{rank}] {name} {sep} {value} ({percent}) {sep} {volume} {sep} {cap}'
def coin_matrix(data): # very retarded way of calculating the longest strings per-column
results = {'symbol':list(),'value':list(),'perc_1h':list(),'perc_24h':list(),'perc_7d':list(),'volume':list(),'cap':list()}
for item in data:
results['symbol'].append(item['symbol'])
results['value'].append(clean_value(item['price']))
for perc in ('1h','24h','7d'):
results['perc_' + perc].append('{:,.2f}%'.format(item['percent'][perc]))
results['volume'].append('${:,}'.format(item['volume']))
results['cap'].append('${:,}'.format(item['market_cap']))
for item in results:
results[item] = len(max(results[item], key=len))
if results['symbol'] < len('Symbol'):
results['symbol'] = len('Symbol')
if results['value'] < len('Value'):
results['value'] = len('Value')
if results['volume'] < len('Volume'):
results['volume'] = len('Volume')
if results['cap'] < len('Market Cap'):
results['cap'] = len('Market Cap')
return results
def coin_table(data):
matrix = coin_matrix(data)
header = color(' {0} {1} {2} {3} {4} {5} {6} '.format('Symbol'.center(matrix['symbol']), 'Value'.center(matrix['value']), '1H'.center(matrix['perc_1h']), '24H'.center(matrix['perc_24h']), '7D'.center(matrix['perc_7d']), 'Volume'.center(matrix['volume']), 'Market Cap'.center(matrix['cap'])), constants.black, constants.light_grey)
lines = [header,]
for item in data:
symbol = item['symbol'].ljust(matrix['symbol'])
value = clean_value(item['price']).rjust(matrix['value'])
perc_1h = color('{:,.2f}%'.format(item['percent']['1h']).rjust(matrix['perc_1h']), percent_color(item['percent']['1h']))
perc_24h = color('{:,.2f}%'.format(item['percent']['24h']).rjust(matrix['perc_24h']), percent_color(item['percent']['24h']))
perc_7d = color('{:,.2f}%'.format(item['percent']['7d']).rjust(matrix['perc_7d']), percent_color(item['percent']['7d']))
volume = '${:,}'.format(item['volume']).rjust(matrix['volume'])
cap = '${:,}'.format(item['market_cap']).rjust(matrix['cap'])
lines.append(' {0} | {1} | {2} {3} {4} | {5} | {6} '.format(symbol,value,perc_1h,perc_24h,perc_7d,volume,cap))
return lines
def color(msg, foreground, background=None):
if background:
return f'\x03{foreground},{background}{msg}{constants.reset}'
else:
return f'\x03{foreground}{msg}{constants.reset}'
def days(date_obj):
return (date_obj-datetime.date.today()).days
def fee(amount, percent):
return amount-(amount*percent)
def is_amount(amount, star=True):
if amount[:1] == '$':
amount = amount[1:]
if amount.isdigit():
return True if int(amount) > 0.0 else False
else:
try:
float(amount)
return True if float(amount) > 0.0 else False
except ValueError:
return True if star and amount == '*' else False
def month_days():
now = datetime.datetime.now()
return calendar.monthrange(now.year, now.month)[1]
def percent_color(percent):
percent = float(percent)
if percent == 0.0:
return constants.grey
elif percent < 0.0:
return constants.brown if percent > -10.0 else constants.red
else:
return constants.green if percent < 10.0 else constants.light_green
def random_int(min, max):
return random.randint(min, max)
def uptime(start):
uptime = datetime.datetime(1,1,1) + datetime.timedelta(seconds=time.time() - start)
return f'{uptime.day-1} Days, {uptime.hour} Hours, {uptime.minute} Minutes, {uptime.second} Seconds'

600
irccex/core/irc.py Normal file
View File

@ -0,0 +1,600 @@
#!/usr/bin/env python
# IRC Cryptocurrency Exchange (IRCCEX) - Developed by acidvegas in Python (https://acid.vegas/irccex)
# irc.py
'''
if using_too_many_if_statements == True:
use_more = True
else:
use_alot_more = True
'''
import datetime
import os
import pickle
import random
import socket
import threading
import time
import config
import constants
import functions
from cmc import CoinMarketCap
if config.connection.ssl:
import ssl
def color(msg, foreground, background=None):
if background:
return f'{constants.color}{foreground},{background}{msg}{constants.reset}'
else:
return f'{constants.color}{foreground}{msg}{constants.reset}'
class IRC(object):
def __init__(self):
self.db = {'bank':dict(),'pool':0.0,'round':1,'score':dict(),'start':datetime.date.today(),'verify':dict(),'wallet':dict()}
self.last = 0
self.last_backup = time.strftime('%I:%M')
self.maintenance = False
self.reward = {'reward':0,'rewards':0,'status':False}
self.slow = False
self.sock = None
self.start = time.time()
def run(self):
if os.path.isfile('data/db.pkl'):
with open('data/db.pkl', 'rb') as db_file:
self.db = pickle.load(db_file)
print('[+] - Restored database!')
Loops.start_loops()
self.connect()
def connect(self):
try:
self.create_socket()
self.sock.connect((config.connection.server, config.connection.port))
self.register()
except socket.error as ex:
print('[!] - Failed to connect to IRC server! (' + str(ex) + ')')
Events.disconnect()
else:
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)
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)
if config.connection.ssl_verify:
ctx.verify_mode = ssl.CERT_REQUIRED
ctx.load_default_certs()
else:
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
self.sock = ctx.wrap_socket(self.sock)
def listen(self):
while True:
try:
data = self.sock.recv(2048).decode('utf-8')
for line in (line for line in data.split('\r\n') if line):
print('[~] - ' + line)
if len(line.split()) >= 2:
Events.handle(line)
except (UnicodeDecodeError,UnicodeEncodeError):
pass
except Exception as ex:
print('[!] - Unexpected error occured. (' + str(ex) + ')')
break
Events.disconnect()
def register(self):
if config.login.network:
Commands.raw('PASS ' + config.login.network)
Commands.raw(f'USER {config.ident.username} 0 * :{config.ident.realname}')
Commands.nick(config.ident.nickname)
class Commands:
def action(chan, msg):
Commands.sendmsg(chan, f'\x01ACTION {msg}\x01')
def check_nick(nick, chan):
if nick in Bot.db['wallet']:
return True
else:
if nick in Bot.db['verify']:
Commands.error(chan, 'Your account is not verified!', 'try again later')
else:
Commands.error(chan, 'You don\'t have an account!', 'use !register to make an account')
return False
def cleanup(nick):
for symbol in [symbol for symbol in Bot.db['wallet'][nick] if not Bot.db['wallet'][nick][symbol]]:
del Bot.db['wallet'][nick][symbol]
if not Bot.db['wallet'][nick]:
del Bot.db['wallet'][nick]
def error(target, data, reason=None):
if reason:
Commands.sendmsg(target, '[{0}] {1} {2}'.format(color('!', constants.red), data, color('({0})'.format(reason), constants.grey)))
else:
Commands.sendmsg(target, '[{0}] {1}'.format(color('!', constants.red), data))
def identify(nick, password):
Commands.sendmsg('NickServ', f'identify {nick} {password}')
def join_channel(chan, key=None):
Commands.raw(f'JOIN {chan} {key}') if key else Commands.raw('JOIN ' + chan)
def mode(target, mode):
Commands.raw(f'MODE {target} {mode}')
def nick(nick):
Commands.raw('NICK ' + nick)
def notice(target, msg):
Commands.raw(f'NOTICE {target} :{msg}')
def oper(user, password):
Commands.raw(f'OPER {user} {password}')
def raw(msg):
Bot.sock.send(bytes(msg + '\r\n', 'utf-8'))
def sendmsg(target, msg):
Commands.raw(f'PRIVMSG {target} :{msg}')
time.sleep(config.throttle.msg)
class Events:
def connect():
if config.connection.modes:
Commands.mode(config.ident.nickname, '+' + config.connection.modes)
if config.login.nickserv:
Commands.identify(config.ident.nickname, config.login.nickserv)
if config.login.operator:
Commands.oper(config.ident.username, config.login.operator)
Commands.join_channel(config.connection.channel, config.connection.key)
def disconnect():
Bot.sock.close()
time.sleep(config.throttle.reconnect)
Bot.connect()
def invite(chan):
if chan == config.connection.channel:
Commands.join_channel(config.connection.channel, config.connection.key)
def kick(chan, kicked):
if kicked == config.ident.nickname and chan == config.connection.channel:
time.sleep(config.throttle.rejoin)
Commands.join_channel(chan, config.connection.key)
def message(nick, chan, msg):
if chan == config.connection.channel:
try:
if msg[:1] in '!@$':
if time.time() - Bot.last < config.throttle.cmd:
if not Bot.slow:
Bot.slow = True
Commands.sendmsg(chan, color('Slow down nerd!', constants.red))
else:
Bot.slow = False
args = msg.split()
if Bot.maintenance and args[0] in ('!cashout','!send','!trade'):
Commands.error(chan, 'Exchange is down for scheduled maintenance!', 'try again later')
else:
if args[0] == '!cashout':
if Commands.check_nick(nick, chan):
if 'USD' not in Bot.db['wallet'][nick]:
Commands.error(chan, 'Insufficent funds.', 'you have no USD in your account')
elif Bot.db['wallet'][nick]['USD'] < config.limits.cashout:
Commands.error(chan, 'Insufficent funds.', f'${config.limits.cashout:,} minimum')
else:
profit = Bot.db['wallet'][nick]['USD']-config.limits.init
amount = functions.fee(profit, config.fees.cashout)
cashout_msg = msg[9:][:100] if len(args) > 1 else Bot.db['bank'][nick][1] if nick in Bot.db['bank'] else 'IM RICH BITCH !!!'
Bot.db['bank'][nick] = (Bot.db['bank'][nick][0]+amount, cashout_msg) if nick in Bot.db['bank'] else (amount, cashout_msg)
Bot.db['pool'] += profit-amount
Bot.db['wallet'][nick]['USD'] = config.limits.init
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')
elif msg == '@stats':
bank_total = 0
global_data = CMC._global()
ticker_data = CMC._ticker()
wallet_total = 0
for item in Bot.db['bank']:
bank_total += Bot.db['bank'][item][0]
for user in Bot.db['wallet']:
for symbol in Bot.db['wallet'][user]:
value = Bot.db['wallet'][user][symbol] if symbol == 'USD' else ticker_data[symbol]['price']*Bot.db['wallet'][user][symbol]
wallet_total += value
Commands.sendmsg(chan, '[{0}]'.format(color('Bot', constants.cyan)))
Commands.sendmsg(chan, ' {0} {1}'.format(color('Backup :', constants.white), Bot.last_backup))
Commands.sendmsg(chan, ' {0} {1}'.format(color('Round :', constants.white), Bot.db['round']))
Commands.sendmsg(chan, ' {0} {1}'.format(color('Uptime :', constants.white), functions.uptime(Bot.start)))
Commands.sendmsg(chan, '[{0}]'.format(color('Market', constants.cyan)))
Commands.sendmsg(chan, ' {0} {1}%'.format(color('BTC Dominance :', constants.white), global_data['btc_dominance']))
Commands.sendmsg(chan, ' {0} {1}%'.format(color('ETH Dominance :', constants.white), global_data['eth_dominance']))
Commands.sendmsg(chan, ' {0} {1:,}'.format(color('Cryptocurrencies :', constants.white), global_data['cryptocurrencies']))
Commands.sendmsg(chan, ' {0} {1:,}'.format(color('Exchanges :', constants.white), global_data['exchanges']))
Commands.sendmsg(chan, ' {0} ${1:,}'.format(color('Market Cap :', constants.white), global_data['market_cap']))
Commands.sendmsg(chan, ' {0} ${1:,}'.format(color('Volume :', constants.white), global_data['volume']))
Commands.sendmsg(chan, '[{0}]'.format(color('Round', constants.cyan)))
Commands.sendmsg(chan, ' {0} {1} {2}'.format(color('Accounts :', constants.white), '{:,}'.format(len(Bot.db['wallet'])), color('(${:,})'.format(int(wallet_total)), constants.grey)))
Commands.sendmsg(chan, ' {0} {1} {2}'.format(color('Bank :', constants.white), '{:,}'.format(len(Bot.db['bank'])), color('(${:,})'.format(int(bank_total)), constants.grey)))
Commands.sendmsg(chan, ' {0} ${1:,}'.format(color('Reward Pool :', constants.white), int(Bot.db['pool'])))
Commands.sendmsg(chan, ' {0} {1:,}'.format(color('Unverified :', constants.white), len(Bot.db['verify'])))
elif msg.startswith('$'):
msg = msg.upper()
if ',' in msg:
seen = set()
coins = [x for x in list(msg[1:].split(','))[:10] if not (x in seen or seen.add(x))]
data = [CMC._ticker()[coin] for coin in coins if coin in CMC._ticker()]
if data:
if len(data) == 1:
Commands.sendmsg(chan, functions.coin_info(data[0]))
else:
for line in functions.coin_table(data):
Commands.sendmsg(chan, line)
else:
Commands.error(chan, 'Invalid cryptocurrency names!')
else:
coin = msg[1:]
if not coin.split('.')[0].isdigit():
if coin in CMC._ticker():
Commands.sendmsg(chan, functions.coin_info(CMC._ticker()[coin]))
else:
Commands.error(chan, 'Invalid cryptocurrency name!')
elif msg == '!bang' and Bot.reward['status']:
if Commands.check_nick(nick, chan):
amount = functions.fee(Bot.reward['reward'], float('0.{0:02}'.format(functions.random_int(5,15)))) if Bot.reward['rewards'] else Bot.db['pool']
Bot.db['wallet'][nick]['USD'] = Bot.db['wallet'][nick]['USD']+amount if 'USD' in Bot.db['wallet'][nick] else amount
Bot.db['pool'] -= amount
if Bot.db['pool']:
Commands.sendmsg(chan, 'You won {0}!'.format(color('${:,}'.format(amount), constants.green)))
Bot.reward['rewards'] -= 1
else:
Commands.sendmsg(chan, 'You won the big {0}!'.format(color('${:,}'.format(amount), constants.green)))
Bot.reward = {'reward':0,'rewards':0,'status':False}
elif msg == '!bank':
if nick in Bot.db['bank']:
clean_bank = dict()
for item in Bot.db['bank']:
clean_bank[item] = Bot.db['bank'][item][0]
richest = sorted(clean_bank, key=clean_bank.get, reverse=True)
Commands.sendmsg(chan, '[{0}] {1} {2} {3}'.format(color('{:02}'.format(richest.index(nick)+1), constants.pink), nick, color('${:,}'.format(int(Bot.db['bank'][nick][0])), constants.green), Bot.db['bank'][nick][1]))
else:
Commands.error(chan, 'You don\'t have any money in the bank!', 'use !cashout to put money in the bank')
elif msg == '!portfolio':
if Commands.check_nick(nick, chan):
total = 0
for symbol in Bot.db['wallet'][nick]:
value = Bot.db['wallet'][nick][symbol] if symbol == 'USD' else CMC._ticker()[symbol]['price']*Bot.db['wallet'][nick][symbol]
total += value
Commands.sendmsg(chan, color('${:,}'.format(int(total)), constants.green))
elif msg == '!register':
if nick not in Bot.db['verify'] and nick not in Bot.db['wallet']:
Bot.db['verify'][nick] = time.time()
Commands.sendmsg(chan, 'Welcome to the IRC Cryptocurrency Exchange! ' + color('(please wait 24 hours while we verify your documents)', constants.grey))
else:
Commands.error(chan, 'Failed to register an account!', 'you already have an account')
elif msg == '!rich':
if Bot.db['bank']:
clean_bank = dict()
for item in Bot.db['bank']:
clean_bank[item] = Bot.db['bank'][item][0]
richest = sorted(clean_bank, key=clean_bank.get, reverse=True)[:10]
for user in richest:
_user = f'{user[:1]}{constants.reset}{user[1:]}'
Commands.sendmsg(chan, '[{0}] {1} {2} {3}'.format(color('{:02}'.format(richest.index(user)+1), constants.pink), _user.ljust(15), color('${:,}'.format(int(Bot.db['bank'][user][0])).ljust(13), constants.green), Bot.db['bank'][user][1]))
Commands.sendmsg(chan, '^ this could be u but u playin...')
else:
Commands.error(chan, 'Yall broke...')
elif msg == '!score':
if nick in Bot.db['score']:
clean_bank = dict()
for item in Bot.db['score']:
clean_bank[item] = Bot.db['score'][item][0]
top = sorted(clean_bank, key=clean_bank.get, reverse=True)
Commands.sendmsg(chan, '[{0}] {1} {2} {3}'.format(color('{:02}'.format(top.index(nick)+1), constants.pink), nick, color(str(Bot.db['score'][nick][0]), constants.cyan), color('${:,}'.format(int(Bot.db['score'][nick][1])), constants.green)))
else:
Commands.error(chan, 'You don\'t have any points!', 'be in the top 10 at the end of the month when the current round ends to get points')
elif msg == '!scores':
if Bot.db['score']:
clean_score = dict()
for item in Bot.db['score']:
clean_score[item] = Bot.db['score'][item][0]
top = sorted(clean_score, key=clean_score.get, reverse=True)[:10]
for user in top:
Commands.sendmsg(chan, '[{0}] {1} {2} {3}'.format(color('{:02}'.format(top.index(user)+1), constants.pink), user.ljust(15), color(str(Bot.db['score'][user][0]).ljust(5), constants.cyan), color('${:,}'.format(int(Bot.db['score'][nick][1])), constants.green)))
Commands.sendmsg(chan, '^ this could be u but u playin...')
else:
Commands.error(chan, 'Yall broke...')
elif msg == '!top':
data = list(CMC._ticker().values())[:10]
for line in functions.coin_table(data):
Commands.sendmsg(chan, line)
elif msg == '!wallet':
if Commands.check_nick(nick, chan):
Commands.sendmsg(chan, color(' Symbol Amount Value ', constants.black, constants.light_grey))
total = 0
for symbol in Bot.db['wallet'][nick]:
amount = Bot.db['wallet'][nick][symbol]
value = amount if symbol == 'USD' else CMC._ticker()[symbol]['price']*amount
Commands.sendmsg(chan, f' {symbol.ljust(8)} | {str(functions.clean_float(amount)).rjust(20)} | {str(functions.clean_value(value)).rjust(20)}')
total += float(value)
Commands.sendmsg(chan, color(f' Total: {str(functions.clean_value(total)).rjust(27)}', constants.black, constants.light_grey))
elif len(args) == 2:
if args[0] in ('!bottom','!top'):
option = args[1].lower()
if option not in ('1h','24h','7d','value','volume'):
Commands.error(chan, 'Invalid option!', 'valid options are 1h, 24h, 7d, value & volume')
else:
data = dict()
for item in CMC._ticker():
data[item] = float(CMC._ticker()[item]['percent'][option])
data = sorted(data, key=data.get, reverse=True)
data = data[-10:] if args[0] == '!bottom' else data[:10]
data = [CMC._ticker()[coin] for coin in data]
for line in functions.coin_table(data):
Commands.sendmsg(chan, line)
elif len(args) == 3:
if args[0] == '!trade':
if Commands.check_nick(nick, chan):
pair = args[1].upper()
if len(pair.split('/')) == 2:
from_symbol, to_symbol = pair.split('/')
if from_symbol in Bot.db['wallet'][nick]:
amount = args[2].replace(',','')
if functions.is_amount(amount):
if amount == '*':
amount = Bot.db['wallet'][nick][from_symbol]
elif amount.startswith('$'):
amount = float(amount[1:]) if from_symbol == 'USD' else float(amount[1:])/CMC._ticker()[from_symbol]['price']
else:
amount = float(amount)
usd_value = amount if from_symbol == 'USD' else CMC._ticker()[from_symbol]['price']*amount
if Bot.db['wallet'][nick][from_symbol] >= amount:
if usd_value >= config.limits.trade:
recv_amount = functions.fee(amount, config.fees.trade)
if functions.check_pair(from_symbol, to_symbol):
from_value = 1 if from_symbol == 'USD' else CMC._ticker()[from_symbol]['price']
to_value = 1 if to_symbol == 'USD' else CMC._ticker()[to_symbol]['price']
recv_amount = (recv_amount*from_value)/to_value
if to_symbol in Bot.db['wallet'][nick]:
Bot.db['wallet'][nick][from_symbol] -= amount
Bot.db['wallet'][nick][to_symbol] += recv_amount
Commands.cleanup(nick)
Bot.db['pool'] += usd_value-functions.fee(usd_value, config.fees.trade)
Commands.sendmsg(chan, 'Trade successful!')
else:
if len(Bot.db['wallet'][nick]) < config.limits.assets:
Bot.db['wallet'][nick][from_symbol] -= amount
Bot.db['wallet'][nick][to_symbol] = recv_amount
Commands.cleanup(nick)
Bot.db['pool'] += usd_value-functions.fee(usd_value, config.fees.trade)
Commands.sendmsg(chan, 'Trade successful!')
else:
Commands.error(chan, f'You can\'t hold more than {config.limits.assets} assets!')
else:
Commands.error(chan, 'Invalid trade pair!')
else:
Commands.error(chan, 'Invalid amount.', f'${config.limits.trade} minimum')
else:
Commands.error(chan, 'Insufficient funds.')
else:
Commands.error(chan, 'Invalid amount argument.')
else:
Commands.error(chan, 'Insufficient funds.')
else:
Commands.error(chan, 'Invalid trade pair.')
elif args[0] == '!value':
amount = args[1]
if functions.is_amount(amount, False):
amount = amount.replace(',','')
symbol = args[2].upper()
if symbol in CMC._ticker():
value = CMC._ticker()[symbol]['price']*float(amount)
if value < 0.01:
Commands.sendmsg(chan, '{0} is worth {1}'.format(color(f'{amount} {symbol}', constants.white), color('${0:,.8f}'.format(value), constants.light_blue)))
else:
Commands.sendmsg(chan, '{0} is worth {1}'.format(color(f'{amount} {symbol}', constants.white), color('${0:,.2f}'.format(value), constants.light_blue)))
else:
Commands.error(chan, 'Invalid cryptocurrency name!')
else:
Commands.error(chan, 'Invalid amount!')
elif len(args) == 4:
if args[0] == '!send':
if Commands.check_nick(nick, chan):
total = 0
for symbol in Bot.db['wallet'][nick]:
total += Bot.db['wallet'][nick]['USD'] if symbol == 'USD' else CMC._ticker()[symbol]['price']*Bot.db['wallet'][nick][symbol]
if total >= config.limits.send:
receiver = args[1].lower()
if receiver in Bot.db['wallet']:
if nick != receiver:
amount = args[2].replace(',','')
symbol = args[3].upper()
if symbol in Bot.db['wallet'][nick]:
if functions.is_amount(amount):
amount = amount.replace(',','')
if amount == '*':
amount = Bot.db['wallet'][nick][symbol]
elif amount.startswith('$'):
amount = float(amount[1:]) if symbol == 'USD' else float(amount[1:])/CMC._ticker()[symbol]['price']
else:
amount = float(amount)
usd_value = amount if symbol == 'USD' else CMC._ticker()[symbol]['price']*amount
if Bot.db['wallet'][nick][symbol] >= amount:
if usd_value >= config.limits.trade:
recv_amount = functions.fee(amount, config.fees.send)
if symbol in Bot.db['wallet'][receiver] or len(Bot.db['wallet'][receiver]) < config.limits.assets:
Bot.db['wallet'][receiver][symbol] = Bot.db['wallet'][receiver][symbol]+recv_amount if symbol in Bot.db['wallet'][receiver] else recv_amount
Bot.db['wallet'][nick][symbol] -= amount
Commands.cleanup(nick)
Bot.db['pool'] += usd_value-functions.fee(usd_value, config.fees.send)
Commands.sendmsg(receiver, '{0} just sent you {1} {2}! {3}'.format(color(nick, constants.light_blue), functions.clean_float(recv_amount), symbol, color('({0})'.format(functions.clean_value(usd_value)), constants.grey)))
Commands.sendmsg(chan, 'Sent!')
else:
Commands.error(chan, f'User can\'t hold more than {config.limits.assets} assets!')
else:
Commands.error(chan, 'Invalid send amount.', f'${config.limits.trade} minimum')
else:
Commands.error(chan, 'Insufficient funds.')
else:
Commands.error(chan, 'Invalid send amount.')
else:
Commands.error(chan, 'Insufficient funds.')
else:
Commands.error(chan, '...Really?')
elif receiver in Bot.db['verify']:
Commands.error(chan, 'User is not verified yet!')
else:
Commands.error(chan, 'User is not in the database.')
else:
Commands.error(chan, 'Insufficent funds!', f'${config.limits.send} minium')
Bot.last = time.time()
except Exception as ex:
if time.time() - Bot.last < config.throttle.cmd:
if not Bot.slow:
Commands.sendmsg(chan, color('Slow down nerd!', constants.red))
Bot.slow = True
else:
Commands.error(chan, 'Command threw an exception.', ex)
Bot.last = time.time()
def nick_in_use():
config.ident.nickname = 'IRCCEX_' + str(functions.random_int(10,99))
Commands.nick(config.ident.nickname)
def handle(data):
args = data.split()
if data.startswith('ERROR :Closing Link:'):
raise Exception('Connection has closed.')
elif args[0] == 'PING':
Commands.raw('PONG ' + args[1][1:])
elif args[1] == constants.RPL_WELCOME:
Events.connect()
elif args[1] == constants.ERR_NICKNAMEINUSE:
Events.nick_in_use()
elif args[1] == constants.INVITE and len(args) == 4:
chan = args[3][1:]
Events.invite(chan)
elif args[1] == constants.KICK and len(args) >= 4:
chan = args[2]
kicked = args[3]
Events.kick(chan, kicked)
elif args[1] == constants.PRIVMSG and len(args) >= 4:
chan = args[2]
nick = args[0].split('!')[0][1:].lower()
msg = ' '.join(args[3:])[1:]
Events.message(nick, chan, msg)
class Loops:
def start_loops():
threading.Thread(target=Loops.backup).start()
threading.Thread(target=Loops.maintenance).start()
threading.Thread(target=Loops.remind).start()
threading.Thread(target=Loops.reward).start()
threading.Thread(target=Loops.round).start()
threading.Thread(target=Loops.verify).start()
def backup():
while True:
time.sleep(3600) # 1H
with open('data/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 maintenance():
while True:
try:
time.sleep(functions.random_int(604800,1209600)) # 7D - 14D
Bot.maintenance = True
Commands.action(config.connection.channel, color('Exchange is going down for scheduled maintenance!', constants.red))
time.sleep(functions.random_int(3600, 86400)) # 1H - 1D
Bot.maintenance = False
Commands.notice(config.connection.channel, color('Maintenance complete! Exchange is back online!', constants.green))
except Exception as ex:
Bot.maintenance = False
print('[!] - Error occured in the maintenance loop! (' + str(ex) + ')')
def remind():
time.sleep(10)
while True:
try:
days = functions.month_days()
now = int(time.strftime('%-d'))
for dayz in (7,14,21):
if days-now == dayz:
Commands.notice(config.connection.channel, 'There is only {0} week(s) left until round {1} ends!'.format(color(str(int(dayz/7)), constants.cyan), color(str(Bot.db['round']), constants.cyan)))
break
except Exception as ex:
print('[!] - Error occured in the reminder loop! (' + str(ex) + ')')
finally:
time.sleep(86400) # 24H
def reward():
while True:
try:
time.sleep(functions.random_int(86400, 259200)) # 1D - 3D
if not Bot.reward['status'] and not Bot.maintenance:
option = functions.random_int(25,50)
Bot.reward = {'reward':Bot.db['pool']/(option*2),'rewards':option,'status':True}
Commands.notice(config.connection.channel, 'There is {1} in the reward pool. Type {2} to grab some cash stacks!'.format(color('${:,}'.format(int(Bot.db['pool'])), constants.green), color('!bang', constants.light_blue)))
except Exception as ex:
print('[!] - Error occured in the reward loop! (' + str(ex) + ')')
def round():
time.sleep(10)
while True:
try:
if time.strftime('%d') == '01':
Bot.maintenance = True
amount = 10 if len(Bot.db['bank']) >= 10 else len(Bot.db['bank'])
if amount:
clean_bank = dict()
for item in Bot.db['bank']:
clean_bank[item] = Bot.db['bank'][item][0]
richest = sorted(clean_bank, key=clean_bank.get, reverse=True)[:amount]
for nick in richest:
if nick in Bot.db['score']:
Bot.db['score'][nick] = (Bot.db['score'][nick][0]+(amount-richest.index(nick)), Bot.db['score'][nick][1]+Bot.db['bank'][nick][0])
else:
Bot.db['score'][nick] = (amount-richest.index(nick), Bot.db['bank'][nick][0])
Commands.notice(config.connection.channel, 'Round {0} is now over! Winners: {1}'.format(color(Bot.db['round'], constants.light_blue), color(', '.join(richest), constants.yellow)))
else:
Commands.notice(config.connection.channel, 'Round {0} is now over! Winners: {1}'.format(color(Bot.db['round'], constants.light_blue), color('None', constants.grey)))
Bot.db = {'bank':dict(),'pool':0.0,'round':Bot.db['round']+1,'score':Bot.db['score'],'verify':dict(),'wallet':dict()}
Commands.action(config.connection.channel, 'Round {0} starts NOW!'.format(color(Bot.db['round'], constants.light_blue)))
Bot.maintenance = False
except Exception as ex:
print('[!] - Error occured in the round loop! (' + str(ex) + ')')
finally:
time.sleep(86400) # 24H
def verify():
time.sleep(10)
while True:
try:
if Bot.db['verify']:
for nick in [nick for nick in Bot.db['verify'] if time.time() - Bot.db['verify'][nick] >= 86400]: # 1D
Bot.db['wallet'][nick] = {'USD':config.limits.init}
del Bot.db['verify'][nick]
Commands.sendmsg(nick, f'Your account is now verified! Here is ${config.limits.init:,} to start trading!')
except Exception as ex:
print('[!] - Error occured in the verify loop! (' + str(ex) + ')')
finally:
time.sleep(3600) # 1H
CMC = CoinMarketCap()
Bot = IRC()

4
irccex/data/cert/.gitignore vendored Normal file
View File

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

12
irccex/data/dbx.py Normal file
View File

@ -0,0 +1,12 @@
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 Normal file
View File

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

20
irccex/irccex.py Normal file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env python
# IRC Cryptocurrency Exchange (IRCCEX) - Developed by acidvegas in Python (https://acid.vegas/irccex)
# irccex.py
import os
import sys
sys.dont_write_bytecode = True
os.chdir(sys.path[0] or '.')
sys.path += ('core',)
print('#'*56)
print('#{0}#'.format(''.center(54)))
print('#{0}#'.format('IRC Cryptocurrency Exchange (IRCCEX)'.center(54)))
print('#{0}#'.format('Developed by acidvegas in Python'.center(54)))
print('#{0}#'.format('https://acid.vegas/irccex'.center(54)))
print('#{0}#'.format(''.center(54)))
print('#'*56)
import irc
irc.Bot.run()