Merge branch 'thelazier-irc_vars' into develop
This commit is contained in:
commit
a886eeca73
@ -39,6 +39,11 @@ class Coin(object):
|
|||||||
VALUE_PER_COIN = 100000000
|
VALUE_PER_COIN = 100000000
|
||||||
CHUNK_SIZE=2016
|
CHUNK_SIZE=2016
|
||||||
STRANGE_VERBYTE = 0xff
|
STRANGE_VERBYTE = 0xff
|
||||||
|
# IRC Defaults
|
||||||
|
IRC_PREFIX = "E_"
|
||||||
|
IRC_CHANNEL = "#electrum"
|
||||||
|
IRC_SERVER = "irc.freenode.net"
|
||||||
|
IRC_PORT = 6667
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def lookup_coin_class(cls, name, net):
|
def lookup_coin_class(cls, name, net):
|
||||||
@ -359,6 +364,8 @@ class Dash(Coin):
|
|||||||
TX_COUNT = 2157510
|
TX_COUNT = 2157510
|
||||||
TX_PER_BLOCK = 4
|
TX_PER_BLOCK = 4
|
||||||
DEFAULT_RPC_PORT = 9998
|
DEFAULT_RPC_PORT = 9998
|
||||||
|
IRC_PREFIX = "D_"
|
||||||
|
IRC_CHANNEL = "#electrum-dash"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def header_hashes(cls, header):
|
def header_hashes(cls, header):
|
||||||
@ -381,3 +388,4 @@ class DashTestnet(Dash):
|
|||||||
TX_COUNT = 132681
|
TX_COUNT = 132681
|
||||||
TX_PER_BLOCK = 1
|
TX_PER_BLOCK = 1
|
||||||
DEFAULT_RPC_PORT = 19998
|
DEFAULT_RPC_PORT = 19998
|
||||||
|
IRC_PREFIX = "d_"
|
||||||
|
|||||||
@ -30,7 +30,6 @@ def port_text(letter, port, default):
|
|||||||
|
|
||||||
class IRC(LoggedClass):
|
class IRC(LoggedClass):
|
||||||
|
|
||||||
PEER_REGEXP = re.compile('(E_[^!]*)!')
|
|
||||||
Peer = namedtuple('Peer', 'ip_addr host ports')
|
Peer = namedtuple('Peer', 'ip_addr host ports')
|
||||||
|
|
||||||
class DisconnectedError(Exception):
|
class DisconnectedError(Exception):
|
||||||
@ -45,9 +44,15 @@ class IRC(LoggedClass):
|
|||||||
version = '1.0'
|
version = '1.0'
|
||||||
self.real_name = '{} v{} {} {}'.format(env.report_host, version,
|
self.real_name = '{} v{} {} {}'.format(env.report_host, version,
|
||||||
tcp_text, ssl_text)
|
tcp_text, ssl_text)
|
||||||
self.nick = 'E_{}'.format(env.irc_nick if env.irc_nick else
|
self.prefix = env.coin.IRC_PREFIX
|
||||||
|
self.nick = '{}{}'.format(self.prefix,
|
||||||
|
env.irc_nick if env.irc_nick else
|
||||||
double_sha256(env.report_host.encode())
|
double_sha256(env.report_host.encode())
|
||||||
[:5].hex())
|
[:5].hex())
|
||||||
|
self.channel = env.coin.IRC_CHANNEL
|
||||||
|
self.irc_server = env.coin.IRC_SERVER
|
||||||
|
self.irc_port = env.coin.IRC_PORT
|
||||||
|
self.peer_regexp = re.compile('({}[^!]*)!'.format(self.prefix))
|
||||||
self.peers = {}
|
self.peers = {}
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
@ -72,7 +77,7 @@ class IRC(LoggedClass):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
connection = reactor.server()
|
connection = reactor.server()
|
||||||
connection.connect('irc.freenode.net', 6667,
|
connection.connect(self.irc_server, self.irc_port,
|
||||||
self.nick, ircname=self.real_name)
|
self.nick, ircname=self.real_name)
|
||||||
connection.set_keepalive(60)
|
connection.set_keepalive(60)
|
||||||
while True:
|
while True:
|
||||||
@ -89,8 +94,8 @@ class IRC(LoggedClass):
|
|||||||
.format(event.type, event.source, event.arguments))
|
.format(event.type, event.source, event.arguments))
|
||||||
|
|
||||||
def on_welcome(self, connection, event):
|
def on_welcome(self, connection, event):
|
||||||
'''Called when we connect to freenode.'''
|
'''Called when we connect to irc server.'''
|
||||||
connection.join('#electrum')
|
connection.join(self.channel)
|
||||||
|
|
||||||
def on_disconnect(self, connection, event):
|
def on_disconnect(self, connection, event):
|
||||||
'''Called if we are disconnected.'''
|
'''Called if we are disconnected.'''
|
||||||
@ -99,20 +104,20 @@ class IRC(LoggedClass):
|
|||||||
|
|
||||||
def on_join(self, connection, event):
|
def on_join(self, connection, event):
|
||||||
'''Called when someone new connects to our channel, including us.'''
|
'''Called when someone new connects to our channel, including us.'''
|
||||||
match = self.PEER_REGEXP.match(event.source)
|
match = self.peer_regexp.match(event.source)
|
||||||
if match:
|
if match:
|
||||||
connection.who(match.group(1))
|
connection.who(match.group(1))
|
||||||
|
|
||||||
def on_quit(self, connection, event):
|
def on_quit(self, connection, event):
|
||||||
'''Called when someone leaves our channel.'''
|
'''Called when someone leaves our channel.'''
|
||||||
match = self.PEER_REGEXP.match(event.source)
|
match = self.peer_regexp.match(event.source)
|
||||||
if match:
|
if match:
|
||||||
self.peers.pop(match.group(1), None)
|
self.peers.pop(match.group(1), None)
|
||||||
|
|
||||||
def on_kick(self, connection, event):
|
def on_kick(self, connection, event):
|
||||||
'''Called when someone is kicked from our channel.'''
|
'''Called when someone is kicked from our channel.'''
|
||||||
self.log_event(event)
|
self.log_event(event)
|
||||||
match = self.PEER_REGEXP.match(event.arguments[0])
|
match = self.peer_regexp.match(event.arguments[0])
|
||||||
if match:
|
if match:
|
||||||
self.peers.pop(match.group(1), None)
|
self.peers.pop(match.group(1), None)
|
||||||
|
|
||||||
@ -123,7 +128,7 @@ class IRC(LoggedClass):
|
|||||||
The users are space-separated in the 2nd argument.
|
The users are space-separated in the 2nd argument.
|
||||||
'''
|
'''
|
||||||
for peer in event.arguments[2].split():
|
for peer in event.arguments[2].split():
|
||||||
if peer.startswith("E_"):
|
if peer.startswith(self.prefix):
|
||||||
connection.who(peer)
|
connection.who(peer)
|
||||||
|
|
||||||
def on_whoreply(self, connection, event):
|
def on_whoreply(self, connection, event):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user