This repository has been archived by the owner on Nov 10, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
lart.py
56 lines (42 loc) · 1.55 KB
/
lart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf8 -*-
"""
lart.py - Luser Attitude Readjustment Tool
Copyright 2014, Matteo Marchesotti https://www.sfwd.ws
Licensed under the Eiffel Forum License 2.
https://sopel.chat
"""
import random
from sopel import commands
@commands('lart')
def lart(bot, trigger):
"""LART (Luser Attitude Readjustment Tool). Throws a random insult to a luser! Usage: .lart <luser>"""
try:
collection = open('.lart.collection', 'r')
except Exception as e:
bot.say("No lart's collection file found. Try with .help addlart")
print e
return
messages = [line.decode('utf-8') for line in collection.readlines()]
collection.close()
if len(messages)== 0:
bot.say("No insult found! Type .help addlart")
return;
if trigger.group(2) is None:
user = trigger.nick.strip()
else:
user = trigger.group(2).strip()
message = random.choice(messages).replace('LUSER', user).encode('utf_8')
bot.say(message)
@commands('addlart')
def addlart(bot, trigger):
"""Adds another insult to bot's collection with: .addlart <insult>. 'insult' _must_ contain 'LUSER' which will be substituted with the name of the luser."""
try:
lart = trigger.group(2).replace('"','\"').encode('utf_8')
collection = open('.lart.collection', 'a')
collection.write("%s\n"%lart)
collection.close()
except Exception as e:
bot.say("Unable to write insult lart's collection file!")
print e
return
bot.say("Thanks %s: Insult added!"%trigger.nick.strip())