Skip to content

Instantly share code, notes, and snippets.

@bloodywing
Last active December 29, 2015 10:09
Show Gist options
  • Select an option

  • Save bloodywing/7655116 to your computer and use it in GitHub Desktop.

Select an option

Save bloodywing/7655116 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
"""Yama's A.T.S.P.-Bot for IRC-Tasks"""
import irc.bot
import irc.strings
import re
import logging
from threading import Timer
from irc.client import ip_numstr_to_quad, ip_quad_to_numstr
irc.client.ServerConnection.buffer_class.errors = 'ignore'
logging.basicConfig(level=logging.DEBUG)
COMMANDS = ExtendedDict()
class ExtendedDict(dict):
""" Hat die gleichen Klassenmethoden wie dict, aber kann erweitert werden mit eigene """
def foo:
return "bar"
class TestBot(irc.bot.SingleServerIRCBot):
def __init__(self, channel, nickname, server, port=6667):
irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
self.channel = channel
def on_nicknameinuse(self, c, e):
c.nick(c.get_nickname() + "_")
def on_welcome(self, c, e):
c.privmsg('nickserv', 'identify 12345')
c.join(self.channel)
def on_join(self, c, e):
if 'kirika' != e.source.nick and e.target == '#terraria-support':
nick = e.source.nick
c.notice(nick, '10Hi 4' + e.source.nick + '10, this is the 4support-chat for A.T.S.P. 10If you need help, type your problem here and 4wait until a Mod or Admin can help.')
c.notice(nick, '10It is only chat, so it can take a while until someone answers.')
c.notice(nick, '10Most answers can be found on our website and forum, give it a look!')
c.notice(nick, '4http://www.yamahi.eu 10and 4http://www.terrariaforum.yamahi.eu')
def on_privmsg(self, c, e):
nick = e.source.nick
c.privmsg(nick, 'Hi, I am a bot. I can\'t answer you. Have a nice day!')
def on_pubmsg(self, c, e):
a = e.arguments[0]
try:
if re.match('^\!\w+', a):
self.do_command(e, a[1:])
elif c.nick in a and e.target in ['#Yamaria', '#Yama']:
c.privmsg(e.target, 'Hi, I am a bot. Please read here how to contact staff: http://bloodys.bit.ly/link')
elif c.nick in a and e.target == '#terraria-support':
c.privmsg(e.target, 'If you need help, type !help')
except TypeError:
pass
#Commands ------>
def do_command(self, e, cmd):
nick = e.source.nick
c = self.connection
#Help commands ------>
if e.target != '#Yamaria':
if cmd == 'trigger':
c.privmsg(e.target, '10Type: 4!help, 4!rules, 4!website, 4!forum, 4!donate, 4!youtube, 4!facebook 10or 4!twitter')
elif cmd == 'help':
c.privmsg(e.target, '10If you need help, just write your problem in 4#terraria-support 10and wait till a Mod or Admin helps. It is only a chat, so it can take to 10 minutes or more till someone answers. Mostly answers are already on our website and forum, give it a look! 4http://www.yamahi.eu 10and 4http://www.terrariaforum.yamahi.eu')
elif cmd == 'rules':
c.privmsg(e.target, '10We have some easy rules for the best gaming expirience on our server: 4http://www.bit.ly/atsp-rules')
elif cmd == 'website':
c.privmsg(e.target, '10This is our website with all the information and external links you will need: 4http://www.yamahi.eu')
elif cmd == 'forum':
c.privmsg(e.target, '10You can post, read news and discussions in the forum: 4http://www.terrariaforum.yamahi.eu')
elif cmd == 'donate':
c.privmsg(e.target, '10If you want to support our good work, just donate with Paypal here: 4http://www.bit.ly/atsp-vip')
elif cmd == 'youtube':
c.privmsg(e.target, '10See our recorded videos from the server: 4http://www.youtube.com/user/theflame90 10and 4http://terrariaforum.yamahi.eu/discussion/114/game-stream-by-yama')
elif cmd == 'facebook':
c.privmsg(e.target, '10Our Facebook page with actual information and a fanbase: 4http://www.facebook.com/atsp.terraria')
elif cmd == 'twitter':
c.privmsg(e.target, '10Follow us on Twitter: 4http://www.twitter.com/ATSPTerraria')
elif e.target == '#Yamaria' and cmd in ['trigger', 'help', 'rules', 'website', 'forum', 'donate', 'youtube', 'facebook', 'twitter']:
c.privmsg(e.target, '4Please join #terraria-support 14(click on it) 4to get help')
#Admin commands ------>
if e.target == '#terraria':
if cmd == 'disconnect':
self.disconnect()
elif cmd == 'die':
self.die()
elif cmd == 'test':
c.privmsg(e.target, 'Wait...')
privmsg = lambda c, channel, msg: c.privmsg(channel, msg)
t = Timer(5.0, privmsg, (c, e.target, 'yorp dood'))
t.start()
def main():
import sys
if len(sys.argv) != 4:
print("Usage: testbot <server[:port]> <channel> <nickname>")
sys.exit(1)
s = sys.argv[1].split(":", 1)
server = s[0]
if len(s) == 2:
try:
port = int(s[1])
except ValueError:
print("Error: Erroneous port.")
sys.exit(1)
else:
port = 6667
channel = sys.argv[2]
nickname = sys.argv[3]
bot = TestBot(channel, nickname, server, port)
bot.start()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment