Files
fulpstation/bot/irchat.py
quartz235@gmail.com 4472cecbd2 Finally ready to like add this now oh man this is a huge thing sort of
Added CC-Nanotrasen, an IRC bot made by Skibiliano and given to us by him under CC-BY-SA 3.0 licensing
WHAT DOES THIS MEAN? It means all servers running this SVN now have the option to use an easy to configure IRC bot capable of relaying adminhelps from ingame to the server/channel of their choice.
- Runs on python 2.6 scripts with psyco support
- Relaying can be toggled from config.txt (so you don't runtime with every adminhelp if you decide not to use it)
- Comes with a bunch of other useful and fun tools too
- Added a new global proc, send2irc(msg,msg2) YOU'LL NEVER GUESS WHAT IT DOES CONSIDERING WHAT I JUST MENTIONED
----msg and msg2 are just what text gets relayed to irc, separated by a |, for instance send2irc(hello, world) would come out as
"CC_NanoTrasen: Hello | World


git-svn-id: http://tgstation13.googlecode.com/svn/trunk@2783 316c924e-a436-60f5-8080-3fe189b3f50e
2011-12-23 17:39:47 +00:00

95 lines
3.4 KiB
Python

import socket
import time
class IRC:
queue = []
partial = ''
def __init__ ( self, network, port, name, hostName, serverName, realName ):
self.network = network
self.port = port
self.hostName = hostName
self.serverName = serverName
self.realName = realName
self.socket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
self.socket.connect ( ( self.network, self.port ) )
self.address = self.socket.getpeername()
self.nick ( name )
self.send ( 'USER ' + self.name + ' ' + self.serverName + ' ' + self.hostName + ' :' + self.realName )
def quit ( self ):
self.send ( 'QUIT' )
self.socket.close()
def send ( self, text ):
count = 0
try:
count += 1
self.socket.send ( text + '\r\n' )
except:
if count > 10:
time.sleep(1)
self.socket.send(text+'\r\n')
else:
count = 0
def nick ( self, name ):
self.name = name
self.send ( 'NICK ' + self.name )
def addressquery(self):
print self.address
aha = socket.gethostbyaddr(str(self.address[0]))
return aha
def recv ( self, size = 2048 ):
commands = self.socket.recv ( size ).split ( '\r\n' )
if len ( self.partial ):
commands [ 0 ] = self.partial + commands [ 0 ]
self.partial = ''
if len ( commands [ -1 ] ):
self.partial = commands [ -1 ]
self.queue.extend ( commands [ :-1 ] )
else:
self.queue.extend ( commands )
def retrieve ( self ):
if len ( self.queue ):
command = self.queue [ 0 ]
self.queue.pop ( 0 )
return command
else:
return False
def dismantle ( self, command ):
if command:
source = command.split ( ':' ) [ 1 ].split ( ' ' ) [ 0 ]
parameters = command.split ( ':' ) [ 1 ].split ( ' ' ) [ 1: ]
if len(parameters) > 0:
if not len ( parameters [ -1 ] ):
parameters.pop()
if command.count ( ':' ) > 1:
parameters.append(command[command.find(":",command.find(":")+1)+1:])
return source, parameters
def privmsg ( self, destination, message ):
self.send ( 'PRIVMSG ' + destination + ' :' + message )
def handshake(self,hexstring):
self.send("PONG :"+hexstring)
def notice ( self, destination, message ):
self.send ( 'NOTICE ' + destination + ' :' + message )
def join ( self, channel ):
self.send ( 'JOIN ' + channel )
def part ( self, channel ):
self.send ( 'PART ' + channel )
def topic ( self, channel, topic = '' ):
self.send ( 'TOPIC ' + channel + ' ' + topic )
def names ( self, channel ):
self.send ( 'NAMES ' + channel )
def invite ( self, nick, channel ):
self.send ( 'INVITE ' + nick + ' ' + channel )
def mode ( self, channel, mode, nick = '' ):
self.send ( 'MODE ' + channel + ' ' + mode + ' ' + nick )
def banon(self,channel,name):
self.mode(channel,"+b",name)
def banoff(self,channel,name):
self.mode(channel,"-b",name)
def kick ( self, channel, nick, reason = '' ):
self.send ( 'KICK ' + channel + ' ' + nick + ' ' + reason )
def who ( self, pattern ):
self.send ( 'WHO ' + pattern )
def whois ( self, nick ):
self.send ( 'WHOIS ' + nick )
def whowas ( self, nick ):
self.send ( 'WHOWAS ' + nick )