chiark / gitweb /
5bd6bc812170c0f6ffc59aef3b74adc774c45b13
[irc.git] / rjk.diff
1 diff -ruN --exclude {arch} --exclude .arch-ids servus--dev--0--patch-2/ChangeLog.d/servus--dev--0 servus--dev--0--patch-4/ChangeLog.d/servus--dev--0
2 --- servus--dev--0--patch-2/ChangeLog.d/servus--dev--0  2005-07-22 23:17:44.000000000 +0100
3 +++ servus--dev--0--patch-4/ChangeLog.d/servus--dev--0  2005-07-22 23:17:45.000000000 +0100
4 @@ -2,6 +2,35 @@
5  # arch-tag: automatic-ChangeLog--rjk@greenend.org.uk--2004/servus--dev--0
6  #
7  
8 +2005-07-22 22:02:48 GMT        Richard Kettlewell <rjk@greenend.org.uk>        patch-4
9 +
10 +    Summary:
11 +      bloody slashers
12 +    Revision:
13 +      servus--dev--0--patch-4
14 +
15 +    * commands.py: slashq command implements slashing of a pair of names
16 +    * Servus-chiark.py: configuration and setup for slash command
17 +
18 +    modified files:
19 +     ChangeLog.d/servus--dev--0 Servus-chiark.py commands.py
20 +
21 +
22 +2005-07-22 21:36:36 GMT        Richard Kettlewell <rjk@greenend.org.uk>        patch-3
23 +
24 +    Summary:
25 +      fix karma storage
26 +    Revision:
27 +      servus--dev--0--patch-3
28 +
29 +    * Servus-chiark.py: save karma file each time it is changed, not just on
30 +      graceful termination; and rename it into place.
31 +      This prevents unnecessary forgetting of karma.
32 +
33 +    modified files:
34 +     ChangeLog.d/servus--dev--0 Servus-chiark.py
35 +
36 +
37  2005-07-22 21:29:40 GMT        Richard Kettlewell <rjk@greenend.org.uk>        patch-2
38  
39      Summary:
40 diff -ruN --exclude {arch} --exclude .arch-ids servus--dev--0--patch-2/Servus-chiark.py servus--dev--0--patch-4/Servus-chiark.py
41 --- servus--dev--0--patch-2/Servus-chiark.py    2005-07-22 23:17:43.000000000 +0100
42 +++ servus--dev--0--patch-4/Servus-chiark.py    2005-07-22 23:17:45.000000000 +0100
43 @@ -19,6 +19,7 @@
44  # Peter Corbett <ptc24@cam.ac.uk>
45  # Matthew Vernon <matthew@debian.org>
46  # Stephen Early <steve@greenend.org.uk>
47 +# Richard Kettlewell <rjk@greenend.org.uk
48  
49  # Acrobat configuration file
50  
51 @@ -32,6 +33,8 @@
52  
53  # Everything else in this file is configuration-specific.
54  
55 +import os
56 +
57  # Most command implementations are stored in a separate module.
58  import commands as c
59  
60 @@ -76,6 +79,15 @@
61         fish,
62         0.1)
63  
64 +slashcfg= ( 
65 +       __load("slashes"),
66 +       ' (while %s watches)',
67 +       "Sorry, but %s stole my pen.",
68 +       "Who do you want to slash?",
69 +       "I have writer's block!",
70 +       fish,
71 +       0.1)
72 +
73  # Hacky command to output the current fishpond state
74  def fishq(bot, cmd, nick, conn, public,f):
75         from irclib import irc_lower
76 @@ -104,20 +116,20 @@
77          karmadb[thing] += amount
78      else:
79          karmadb[thing] = amount
80 +    savekarma()
81  def savekarma():
82 +    tmp = "%s.tmp" % karmafilename
83      try:
84 -        f = open(karmafilename, "w")
85 +        f = open(tmp, "w")
86          cPickle.dump(karmadb, f)
87          f.close()
88 -    except IOError:
89 -        sys.stderr.write("Problems dumping karma: probably lost :(")
90 +       os.rename(tmp, karmafilename)
91 +    except IOError, e:
92 +        sys.stderr.write("error writing karma: %s" % e)
93  
94 -# When the bot exits we should save the karma db
95  def quit(bot,cmd,nick,conn,public):
96 -    savekarma()
97      c.quitq(bot,cmd,nick,conn,public)
98  def reload(bot,cmd,nick,conn,public):
99 -    savekarma()
100      c.reloadq(bot,cmd,nick,conn,public)
101  
102  # Command processing: whenever something is said that the bot can hear,
103 @@ -130,6 +142,7 @@
104             "karmadel": (c.karmadelq,karmadb),
105              "info": (c.infoq,karmadb),
106              "trout": (c.troutq,troutcfg),
107 +           "slash": (c.slashq, slashcfg),
108             "fish": (fishq,fish),
109              "flirt": (c.troutq,flirtcfg),
110             "quiet": (c.nofishq,fish),
111 diff -ruN --exclude {arch} --exclude .arch-ids servus--dev--0--patch-2/commands.py servus--dev--0--patch-4/commands.py
112 --- servus--dev--0--patch-2/commands.py 2005-07-22 23:17:43.000000000 +0100
113 +++ servus--dev--0--patch-4/commands.py 2005-07-22 23:17:45.000000000 +0100
114 @@ -90,6 +90,53 @@
115      conn.action(bot.channel, trout_msg % target)
116      fishpond.cur_fish-=1
117  
118 +# slash a pair
119 +def slashq(bot, cmd, nick, conn, public, cfg):
120 +    fishlist=cfg[0]
121 +    selfslash=cfg[1]
122 +    quietmsg=cfg[2]
123 +    notargetmsg=cfg[3]
124 +    nofishmsg=cfg[4]
125 +    fishpond=cfg[5]
126 +
127 +    fish_quota(fishpond)
128 +    if fishpond.DoS:
129 +        conn.notice(nick, quietmsg%fishpond.Boring_Git)
130 +       return
131 +    if fishpond.cur_fish<=0:
132 +        conn.notice(nick, nofishmsg)
133 +       return
134 +    target = string.join(cmd.split()[1:])
135 +    who = cmd.split()[1:]
136 +    if len(who) < 2:
137 +       conn.notice(nick, "it takes two to tango!")
138 +       return
139 +    elif len(who) > 2:
140 +       conn.notice(nick, "we'll have none of that round here")
141 +       return
142 +    me = bot.connection.get_nickname()
143 +    slash_msg = random.choice(fishlist)
144 +    # The bot won't slash people with themselves
145 +    if irc_lower(who[0]) == irc_lower(who[1]):
146 +       conn.notice(nick, "oooooh no missus!")
147 +       return
148 +    # The bot won't slash with itself, instead slashing the requester
149 +    for n in [0,1]:
150 +       if irc_lower(me) == irc_lower(who[n]):
151 +           who[n] = nick
152 +    # Perhaps someone asked to slash themselves with the bot then we get
153 +    if irc_lower(who[0]) == irc_lower(who[1]):
154 +       conn.notice(nick, "you wish!")
155 +       return
156 +    # There's a chance the game may be given away if the request was not
157 +    # public...
158 +    if not public:
159 +       if random.random()<=selfslashchance:
160 +           slash_msg=slash_msg+(selfslash%nick)
161 +
162 +    bot.automsg(public,nick, slash_msg % (who[0], who[1]))
163 +    fishpond.cur_fish-=1
164 +
165  # Shut up trouting for a minute
166  def nofishq(bot, cmd, nick, conn, public, fish):
167      fish.cur_fish=0