Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spam Killer [XCHAT PYTHON]
#1
If a message is the same the last 5 lines, and if the names are different, then it will put the message into a KOS(kill on site) list for 3 minutes and whoever says the message during that time will automatically get killed. Hopefully will be useful to help combat people who uses bots to spam the IRC since they normally will enter a static message in the spam.

I plan on adding stuff for changing the default time, adding kills on text yourself, viewing the bantexts list, removing items in the list easily, adding unlimited time text kills when adding them yourself. All using an xchat.hook_command()

Code:
import xchat, threading
__module_name__ = "Bot Kill"
__module_version__ = '1.0'
__module_description__ = "Kills multiple spammers using same message"
lastfour = []
bantexts = []
times = []
def addsec():
    timedata = threading.local()
    if times[len(times)-1]['time'] == 0:
        global b
        b = len(times)-1
    timedata.pos = b
    times[timedata.pos]['time'] += 1
    if not times[timedata.pos]['time'] == 179:
        t = threading.Timer(1.0,addsec)
        t.start()
def SpamCheck(word, word_eol, userdata):
    num = 0
    cont = True
    name, msg = word[0], word[1]
    if bantexts:
        if msg in bantexts:
            xchat.command('KILL '+name+' SpamCheck Script')
            cont = False
    lastfour.append([name,msg])
    if cont:  
        if len(lastfour) == 5:
            del lastfour[0]
            while num <= len(lastfour)-2:
                if num == 2:
                    if not name == lastfour[2][0]:
                        bantexts.append(msg)
                        times.append({'time':0})
                        addsec()
                        xchat.command('echo Adding KOS for "'+msg+'", will remove in 3 minutes.')
                        xchat.command('KILL '+name+' SpamCheck Script')
                        xchat.hook_timer(180000,time)
                    num += 1
                if msg == lastfour[num][1]:
                    num += 1
                else:
                    break
def time(userdata):
    global bantexts
    xchat.command('echo Removed KOS for "'+bantexts[0]+'".')
    del bantexts[0]
    del times[0]
    return xchat.EAT_NONE
def Menu(word, word_eol, userdata):
    cont = False
    try:#FOR ADDING ON OTHER OPTIONS NOT YET PRESENT
        if word[1] == '-a' | word[1] == '-r':
            cont = True
    except:
        xchat.command('echo --------Kill List--------')
        if len(bantexts) == 0:
            xchat.command('echo *No kill texts currently.')
        else:
            for ban in bantexts:
                xchat.command('echo *Text: "'+ban+'".')
                xchat.command('echo **Time left: '+str(180-times[bantexts.index(ban)]['time'])+' seconds.')
        xchat.command('echo -------------------------')
xchat.hook_command('sc', Menu)
xchat.hook_print('Channel Message', SpamCheck)
xchat.hook_print('Channel Action Hilight', SpamCheck)
xchat.hook_print('Channel Msg Hilight', SpamCheck)
[Image: sig.php]
Reply
#2
Freaking awsome Nyx- !!!!
I'll steal you this as it is useful, thanks for sharing!!!
Reply
#3
edited the code, now for each ban added, it also adds a timer so you can track the length of them using /sc

example of the kill list, accessible through /sc :
(yours will only echo, i just changed mine to msg so i can show it off in irc lol, easy to change though)
[Image: 25gw11y.png]

next step: adding sc -a, and sc -r for adding and removing bans yourself ^__^
[Image: sig.php]
Reply
#4
Awsome, I really don't have better words..... Just AWSOME!
That's a really nice update, and I hope to see the next soon, can't wait actually!!! Tongue

I see you are alreay using it in the HF IRC channel, but I don't get the "!hunt" thing!

edit:
What if my bot uses an list of strings for spaming, so it posts different messages, that will not kill him, right?
Reply
#5
(12-18-2009, 05:15 PM)Master of The Universe Wrote: Awsome, I really don't have better words..... Just AWSOME!
That's a really nice update, and I hope to see the next soon, can't wait actually!!! Tongue

I see you are alreay using it in the HF IRC channel, but I don't get the "!hunt" thing!

edit:
What if my bot uses an list of strings for spaming, so it posts different messages, that will not kill him, right?

nah, lol. i may add support for that in the future by logging more lines and dividing it by the number of unique messages to see which are spam which are not ect, not sure. but atm the script is completely butchered and i plan on taking a break from it. its giving ALOT of trouble lol

heres what i have, doesnt really work but meh cant hurt showing lol: http://pastebin.com/m47c5dfc
Code:
import xchat, threading
__module_name__ = "Bot Kill"
__module_version__ = '1.0'
__module_description__ = "Kills multiple spammers using same message"
lastfour = []
bantexts = []
times = []
minutes = 3
"""
PROBLEMS:
ONE TIMER WORKS WELL, WHEN YOU ADD A SECOND TIMER, STOPS FIRST, DOUBLE THREADS SECOND
MENU IS STILL fudged
"""
def addsec():
    timedata = threading.local()
    if times[len(times)-1]['time'] == 0:
        global b
        b = len(times)-1
    timedata.pos = b
    try:
        times[timedata.pos]['time'] += 1
        if not times[timedata.pos]['time'] == minutes*60-2:
            t = threading.Timer(1.0,addsec)
            t.start()
    except:
        pass
def SpamCheck(word, word_eol, userdata):
    num = 0
    cont = True
    name, msg = word[0], word[1]
    if bantexts:
        if msg in bantexts:
            xchat.command('KILL '+name+' SpamCheck Script')
            cont = False
    lastfour.append([name,msg])
    if cont:  
        if len(lastfour) == 4:
            while num <= len(lastfour)-1:
                if num == 3:
                    if not name == lastfour[2][0]:
                        bantexts.append(msg)
                        times.append({'time':0})
                        addsec()
                        xchat.command('echo Adding KOS for "'+msg+'", will remove in '+str(minutes)+' minutes.')
                        xchat.command('KILL '+name+' SpamCheck Script')
                        xchat.hook_timer(minutes*60*1000,time)
                    num += 1
                if msg == lastfour[num][1]:
                    num += 1
                else:
                    break
            del lastfour[0]
def time(userdata):
    global bantexts
    xchat.command('echo Removed KOS for "'+bantexts[0]+'".')
    del bantexts[0]
    del times[0]
    return xchat.EAT_NONE
def Menu(word, word_eol, userdata):
    append = False
    remove = False
    global minutes
    try:
        if word[1] == "-a" | word[1] == "a":
            append = True
        if word[1] == "-r" | word[1] == "r":
            remove = True
    except:
        pass
    if not append|remove:
        xchat.command('echo --------Kill List--------')
        if len(bantexts) == 0:
            xchat.command('echo *No kill texts currently.')
        else:
            for ban in bantexts:
                xchat.command('echo *Text: "'+ban+'".')
                xchat.command('echo **Time left: '+str(minutes*60-times[bantexts.index(ban)]['time'])+' seconds.')
                if not bantexts.index(ban) == len(bantexts)-1:
                    xchat.command('echo --------')
        xchat.command('echo -------------------------')
    if append:
        total = len(word)-1
        msg = []
        if word[len(word)-1].isdigit():
            time = word[len(word)-1]
            total = len(word)-2
        for i in range(2,total):
            msg.append(word[i])
        btext = ' '.join(msg)
        bantexts.append(btext)
        times.append({'time':0})
        addsec()
    if remove:
        msg = []
        for i in range(2,len(word)-1):
            msg.append(word[i])
        btext = ' '.join(msg)
        num = 0
        while num <= len(bantexts)-1:
            if bantexts[num][1] == btext:
                xchat.command('echo Removed KOS for "'+bantexts[0]+'".')
                del bantexts[num]
                del timer[num]
                break
            num = num + 1
xchat.hook_command('sc', Menu)
xchat.hook_print('Channel Message', SpamCheck)
xchat.hook_print('Channel Action Hilight', SpamCheck)
xchat.hook_print('Channel Msg Hilight', SpamCheck)
[Image: sig.php]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Help Dεlluzion 3 1,749 09-30-2019, 12:59 AM
Last Post: samsmith001
  Simple Python Python Compiler Canoris 21 8,340 06-01-2011, 06:30 PM
Last Post: Filefinder
  Python 2 vs 3? Jake 8 2,218 12-11-2010, 04:13 PM
Last Post: Bursihido
  Python help Kharnage 2 743 02-12-2010, 09:07 PM
Last Post: Kharnage
  "==" and "is" in Python Canoris 1 737 02-07-2010, 03:55 PM
Last Post: uber1337

Forum Jump:


Users browsing this thread: 1 Guest(s)