|
1 |
| - |
2 |
| -AUTHOR="ekimekim (based on sleepyparadox's 'sp_opcolor')" |
3 |
| - |
4 |
| -DESCRIPTION= """A plugin that highlights usernames in chat. |
5 |
| -Has different colours for ops, logged in users, not logged in users, and yourself. |
6 |
| -Colours have sensible defaults but are configurable with in-game commands: |
7 |
| - /colors help |
8 |
| - /colors TYPE COLOR |
9 |
| -""" |
10 |
| - |
11 |
| -from packet_decoder import Packet |
12 |
| -from helpers import ops, color |
13 |
| - |
14 |
| -opColor = color('red') |
15 |
| -userColor = color('dark cyan') |
16 |
| - |
17 |
| -def on_start(): |
18 |
| - cmd.register('/color (.*)', on_command) |
19 |
| - |
20 |
| -def on_packet(packet, user, to_server): |
21 |
| - if packet.name() == 'Chat message': |
22 |
| - #Highlight admin names in red |
23 |
| - if not to_server: |
24 |
| - for op in ops(): |
25 |
| - #insert op color flag before name and normal color flag after name |
26 |
| - packet.data['text'] = packet.data['text'].replace(op, opColor + op + color('white')) |
27 |
| - packet.data['text'] = packet.data['text'].replace(user.username, userColor + user.username + color('white')) |
28 |
| - |
29 |
| - #replace 'bitblitz' with developer name 'Sleepy Paradox' |
30 |
| - packet.data['text'] = packet.data['text'].replace(u'bitblitz', u'Sleepy Paradox') |
31 |
| - #return edited packet |
32 |
| - return packet |
33 |
| - |
34 |
| -HELP = """Chat color commands: |
35 |
| -/color help - This message |
36 |
| -/color colors - List available colors |
37 |
| -/color all X - set all chat messages to X |
38 |
| -/color active X - set logged in usernames to X |
39 |
| -/color inactive X - set logged out usernames to X |
40 |
| -/color me X - set yourself to appear as X |
41 |
| -___Note: Only you see the new color, not everyone. |
42 |
| -/color ops X - set ops to appear as X |
43 |
| -Replace X with the color you want, as given by /color colors.""" |
44 |
| - |
45 |
| -def on_command(message, user, command): |
46 |
| - verb, value = command.split(' ', 1) |
47 |
| - if verb == 'help': |
48 |
| - user.tell(HELP) |
49 |
| - elif verb in user.setcolors: |
50 |
| - if value in color.colors |
| 1 | + |
| 2 | +AUTHOR="ekimekim (based on sleepyparadox's 'sp_opcolor')" |
| 3 | + |
| 4 | +DESCRIPTION= """A plugin that highlights usernames in chat. |
| 5 | +Has different colours for ops, logged in users, not logged in users, and yourself. |
| 6 | +Colours have sensible defaults but are configurable with in-game commands: |
| 7 | + /colors help |
| 8 | + /colors TYPE COLOR |
| 9 | +""" |
| 10 | + |
| 11 | +from packet_decoder import Packet |
| 12 | +from helpers import ops, color, colors, all_users, active_users, tell |
| 13 | +import player_cmd as cmd |
| 14 | + |
| 15 | +defaults = { |
| 16 | + 'all': color('white'), |
| 17 | + 'inactive': color('dark gray'), |
| 18 | + 'active': color('gray'), |
| 19 | + 'ops': color('red'), |
| 20 | + 'me': color('dark cyan') |
| 21 | +} |
| 22 | + |
| 23 | +users = {} |
| 24 | + |
| 25 | +def on_start(): |
| 26 | + cmd.register('/color (.*)', on_command) |
| 27 | + cmd.register('/color ?', no_command) |
| 28 | + |
| 29 | +def on_packet(packet, user_obj, to_server): |
| 30 | + if packet.name() == 'Chat message' and not to_server: |
| 31 | + prefs = users.get(user_obj.username, defaults) |
| 32 | + offlines = dict([(user, prefs['inactive']) for user in all_users()]) |
| 33 | + onlines = dict([(user, prefs['active']) for user in active_users()]) |
| 34 | + ops_dict = dict([(user, prefs['ops']) for user in ops()]) |
| 35 | + player = {user_obj.username: prefs['me']} |
| 36 | + names = {} |
| 37 | + names.update(offlines) |
| 38 | + names.update(onlines) |
| 39 | + names.update(ops_dict) |
| 40 | + names.update(player) |
| 41 | + packet.data['text'] = prefs['all'] + packet.data['text'] |
| 42 | + for name in names: |
| 43 | + packet.data['text'] = packet.data['text'].replace(name, names[name] + name + prefs['all']) |
| 44 | + return packet |
| 45 | + |
| 46 | +HELP = """Chat color commands: |
| 47 | +/color help - This message |
| 48 | +/color colors - List available colors |
| 49 | +/color all X - set all chat messages to X |
| 50 | +/color active X - set logged in usernames to X |
| 51 | +/color inactive X - set logged out usernames to X |
| 52 | +/color me X - set yourself to appear as X |
| 53 | +___Note: Only you see the new color, not everyone. |
| 54 | +/color ops X - set ops to appear as X |
| 55 | +Replace X with the color you want, as given by /color colors.""" |
| 56 | + |
| 57 | +def on_command(message, user, command): |
| 58 | + parts = command.split(' ', 1) |
| 59 | + if len(parts) == 2: |
| 60 | + verb, value = parts |
| 61 | + else: |
| 62 | + verb = parts[0] |
| 63 | + if verb == 'help': |
| 64 | + tell(user, HELP) |
| 65 | + elif verb == 'colors': |
| 66 | + for c in colors: |
| 67 | + prefs = users.get(user.username, defaults) |
| 68 | + tell(user, 'color: %s"%s"%s' % (color(c), c, prefs['all'])) |
| 69 | + elif verb in defaults: |
| 70 | + if value in colors: |
| 71 | + prefs = users.get(user.username, defaults.copy()) |
| 72 | + prefs[verb] = color(value) |
| 73 | + users[user.username] = prefs |
| 74 | + else: |
| 75 | + tell(user, 'color: That is not a valid color!') |
| 76 | + else: |
| 77 | + tell(user, 'color: Bad command. Try "/color help"') |
| 78 | + |
| 79 | + |
| 80 | +def no_command(message, user): |
| 81 | + tell(user, 'Modify user colors! Type "/color help".') |
0 commit comments