teelive

louizlouiz
Added on 2009-02-07 03:33:29
teelive - Show - Edit - Download
#$ neutron_plugin 01
# -*- coding:Utf-8 -*-
#
# Plugin who can say what's currently happening on a teeworlds server
#
# © 2009 Le Coz Florent <louizatakk@fedoraproject.org>
#
# Licensed under WTFPL Version 2 as published by Sam Hocevar 
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
#  0. You just DO WHAT THE FUCK YOU WANT TO.
 
 
import gobject
 
# the file where the server's message are located
# must be readable at least
FILE = '/home/manu/teeworlds_out'
# the room where you want the messages to be sent
ROOM = 'teeworlds@chat.jabberfr.org'
 
class Teelive(object):
    def __init__(self):
        self.last = '';
        self.started = True
        self.weapons={'0': 'le marteau', '1': 'le pistolet', '2': 'le shotgun', '3': 'le bazooka', '4': 'le laser', '5': 'le katana'}
 
    def get_last_event(self):
        if not self.started:
            return True
        fd = open(FILE, 'r')
        new = fd.readlines()[-1]
        if new != self.last:
            if self.last != '':
                self.parse_line(new)
            self.last = new
            return True
        else:
            return True
 
    def parse_line(self, p):
        if 'leave player' in p:
            ms = p[p.find(":", p.find(":")+1)+1:-2] + ' a quitté la partie.'
        elif 'team_join' in p:
            ms = p.split("'")[1][p.split("'")[1].find(":")+1:] + ' a rejoint la partie.'
        elif 'kill' in p.split():
            n = p.find("killer='") + len("killer='") + 2
            m = p.find("' victim='")
            o = p.find("' weapon=")
            killer = p[n:m]
            victim = p[m+len("' victim='")+2:o]
            weapon = p[o+len("' weapon="):o+len("' weapon=")+1]
            if killer == victim:
                ms = killer + ' s\'est suicidé'
            else:
                ms = killer + ' a tué ' + victim
            try:
                ms += ' avec ' + self.weapons[weapon] + '.'
            except:
                ms += ' avec le décor, sûrement.'
        else:
            return False
        msg(ROOM, ms)
        return True
        
    def start(self, *args):
        if self.started == False:
            msg(ROOM, "Je vais être causant, pour m'arrêter, dites « !tg »")
            self.started = True
 
    def stop(self, *args):
        if self.started == True:
            msg(ROOM, "Ok, je me tais.")
            self.started = False
 
teelive = Teelive()
register_command_handler(teelive.start, '!teelive')
register_command_handler(teelive.stop, '!tg')