🢀 irccex :: e780d53


commit e780d535851e9b9e7bd1d66c8e74d75146ad2f21
Author: acidvegas <acid.vegas@acid.vegas>
Date:   Mon Jun 24 22:56:57 2019 -0400

    Initial commit

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..69997e8
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,15 @@
+ISC License
+
+Copyright (c) 2019, 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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..9ac5484
--- /dev/null
+++ b/README.md
@@ -0,0 +1,118 @@
+# 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.)*
+* [PySocks](https://pypi.python.org/pypi/PySocks) *(**Optional:** For using the `proxy` setting.)*
+
+###### 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 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. |
+| @patreons | Shoutouts to all the IRCCEX patreons. |
+| @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> | 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)
+
+Major shout-outs & thanks to all the current pledgers:
+* nk9k *($5/M)*
+* all patreons that wish to remain anonymous *(yall know who you are)*
+
+The IRCCEX project is completely open source & non-profit, though any support/pledges will help in motivation towards more development and adding new features!
+
+###### Changelog
+* Output of !wallet is now condensed, calculated based on the data it needs to return.
+* More information returned from !stats, including global market statistics * more.
+* Included a comment about CoinMarketCaps APIv2 in the coinmarketmap.py file. *(APIv2 will not be used until November when APIv1 expires)*
+* Fixed coins reporting in scientific notation from !wallet replies.
+
+Follow us on Twitter ([@irccex](https://twitter.com/irccex)) for the latest news and updates!
+
+###### 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)*
+* Hedge Funds - Either pre-create or allow people to register an account as a hedge fun where they can invest their money a select amount of coins and then lock it. That accounts wallet now becomes a "coin", where you can invest money into it which causes its value to go up.
+* 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).
+* 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.
+* **Royal Rumble** - Round lasts a week and the top player in the bank will score 25 points.
+* **B2B Race** - Round lasts until 5 people make 1 B2B and will score 10 points each.
+* **Food Fight** - Round lasts 3 days. You can only trade FOOD cryptocurrencies. The top 10 players in the bank will score.
+
+We are running IRCCEX actively in **#exchange** on **EFNet** and **#pumpcoin** on **SuperNETs**, come chat with us, make some money, and share ideas!
+
+###### Mirrors
+- [acid.vegas](https://acid.vegas/irccex) *(main)*
+- [SuperNETs](https://git.supernets.org/pumpcoin/irccex)
+- [GitHub](https://github.com/pumpcoin/irccex)
+- [GitLab](https://gitlab.com/pumpcoin/irccex)
diff --git a/irccex/core/config.py b/irccex/core/config.py
new file mode 100644
index 0000000..66c2a6d
--- /dev/null
+++ b/irccex/core/config.py
@@ -0,0 +1,51 @@
+#!/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
+	proxy      = None
+	ipv6       = False
+	ssl        = False
+	ssl_verify = False
+	vhost      = None
+	channel    = '#pumpcoin'
+	key        = 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 settings:
+	log      = False
+	modes    = None
+
+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%
diff --git a/irccex/core/constants.py b/irccex/core/constants.py
new file mode 100644
index 0000000..825c6ef
--- /dev/null
+++ b/irccex/core/constants.py
@@ -0,0 +1,223 @@
+#!/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'
+
+# Hedge Funds
+funds = {
+	'DRUG'   : {'coins':('CANN','DOPE','DMT','HIGH','KLC','LEAF','MAR','POT','SMOKE','THC'), 'description':'INVEST IN DRUGS! The HIGHEST Gains!'},
+	'FOOD'   : {'coins':('BERRY','BLT','BRD','CHIPS','CANDY','EGG','HONEY','MINT','ONION','PIE','SALT','SUB','WINGS'), 'description':'The tastiest fund on the market, indexing all snack coins!'},
+	'GALAXY' : {'coins':('BSTAR','EARTH','MARS','MER','MOON','NAS','ORE','PLU','SPACE','STAR','STARS'), 'description':'Most coins go to the MOON but the GALAXY FUND is out of this world!'}
+}
+
+# Other
+maintenance_lock = ('!cashout','!wallet','!register','!send','!trade')
diff --git a/irccex/core/debug.py b/irccex/core/debug.py
new file mode 100644
index 0000000..f24908e
--- /dev/null
+++ b/irccex/core/debug.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+# IRC Cryptocurrency Exchange (IRCCEX) - Developed by acidvegas in Python (https://acid.vegas/irccex)
+# debug.py
+
+import ctypes
+import logging
+import os
+import sys
+import time
+
+from logging.handlers import RotatingFileHandler
+
+import config
+
+def alert(msg):
+	logging.debug('[+] - ' + msg)
+
+def check_privileges():
+	if check_windows():
+		return True if ctypes.windll.shell32.IsUserAnAdmin() else False
+	else:
+		return True if not os.getuid() or not os.geteuid() else False
+
+def check_version(major):
+	return True if sys.version_info.major == major else False
+
+def check_windows():
+	return True if os.name == 'nt' else False
+
+def error(msg, reason=None):
+	logging.debug(f'[!] - {msg} ({reason})') if reason else logging.debug('[!] - ' + msg)
+
+def error_exit(msg):
+	raise SystemExit('[!] - ' + msg)
+
+def info():
+	os.system('cls') if check_windows() else os.system('clear')
+	logging.debug('#'*56)
+	logging.debug('#{0}#'.format(''.center(54)))
+	logging.debug('#{0}#'.format('IRC Cryptocurrency Exchange (IRCCEX)'.center(54)))
+	logging.debug('#{0}#'.format('Developed by acidvegas in Python'.center(54)))
+	logging.debug('#{0}#'.format('https://acid.vegas/irccex'.center(54)))
+	logging.debug('#{0}#'.format(''.center(54)))
+	logging.debug('#'*56)
+
+def irc(msg):
+	logging.debug('[~] - ' + msg)
+
+def setup_logger():
+	stream_handler = logging.StreamHandler(sys.stdout)
+	if config.settings.log:
+		file_handler = RotatingFileHandler(os.path.join(os.path.join('data','logs'), 'irccex.log'), maxBytes=256000, backupCount=3)
+		logging.basicConfig(level=logging.NOTSET, format='%(asctime)s | %(message)s', datefmt='%I:%M:%S', handlers=(file_handler,stream_handler))
+	else:
+		logging.basicConfig(level=logging.NOTSET, format='%(asctime)s | %(message)s', datefmt='%I:%M:%S', handlers=(stream_handler,))
diff --git a/irccex/core/functions.py b/irccex/core/functions.py
new file mode 100644
index 0000000..c2a1488
--- /dev/null
+++ b/irccex/core/functions.py
@@ -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'
diff --git a/irccex/core/irc.py b/irccex/core/irc.py
new file mode 100644
index 0000000..5b7007e
--- /dev/null
+++ b/irccex/core/irc.py
@@ -0,0 +1,605 @@
+#!/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 debug
+import functions
+from coinmarketcap 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)
+			debug.alert('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:
+			debug.error('Failed to connect to IRC server.', 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):
+					debug.irc(line)
+					if len(line.split()) >= 2:
+						Events.handle(line)
+			except (UnicodeDecodeError,UnicodeEncodeError):
+				pass
+			except Exception as ex:
+				debug.error('Unexpected error occured.', 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.settings.modes:
+			Commands.mode(config.ident.nickname, '+' + config.settings.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 constants.maintenance_lock:
+							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 == '@patreons':
+									Commands.sendmsg(chan, '[{0}] Shoutouts to eraser, nk9k, & all anonymous patreons! {1}'.format(color('Patreons', constants.cyan), color('(https://patreon.com/irccex)', constants.grey)))
+								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('Cryptocurrencies :', constants.white), global_data['cryptocurrencies']))
+									Commands.sendmsg(chan, '  {0} {1:,}'.format(color('Markets          :', constants.white), global_data['markets']))
+									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]
+									options = {'1h':'percent_change_1h','24h':'percent_change_24h','7d':'percent_change_7d','value':'price','volume':'24h_volume_usd'}
+									try:
+										option = options[option.lower()]
+									except KeyError:
+										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][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):