Skip to content

Commit

Permalink
Add easy text formatting when messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
Gwildor committed Mar 30, 2014
1 parent f49d68d commit 5db27fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pyromancer/commands/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ def greeting(match):
def say(match):
for part in match[1].split(', '):
yield 'Saying {}', part


@command(r'colors')
def colors(match):
return '{u}{k}04C{k}05o{k}06l{k}o{k}07r{k}08{k}09s{k}!'
12 changes: 10 additions & 2 deletions pyromancer/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,20 @@ def msg(self, message, *args, **kwargs):
self.line.target

if not raw:
kw = {
'm': self,
'b': chr(2),
'k': chr(3),
'u': chr(31),
}
kw.update(kwargs)

try:
message = message.format(*args, m=self, **kwargs)
message = message.format(*args, **kw)
except IndexError:
if len(args) == 1 and isinstance(args[0], list):
# Message might be: msg, [arg1, arg2], kwargs
message = message.format(*args[0], m=self, **kwargs)
message = message.format(*args[0], **kw)
else:
raise

Expand Down

0 comments on commit 5db27fb

Please sign in to comment.