Browse Source

Refactoring: add pick_sentence()

Issue: #4
master
Matteo Cypriani 3 years ago
parent
commit
a7bf447fe3
1 changed files with 11 additions and 3 deletions
  1. +11
    -3
      kaabot.py

+ 11
- 3
kaabot.py View File

@@ -291,13 +291,21 @@ class KaaBot(sleekxmpp.ClientXMPP):
mtype='chat')

def send_insult(self, nick, dest):
insults = self.vocabulary['insults']
i = random.randint(0, len(insults) - 1)
insult = insults[i].format(nick=nick)
insult = self.pick_sentence('insults').format(nick=nick)
self.send_message(mto=dest,
mbody=insult,
mtype='groupchat')

def pick_sentence(self, type):
"""Returns a random sentence picked in the loaded vocabulary.

`type` can be any known category of the vocabulary file, e.g. 'insults'.
No substitution is done to the returned string.
"""
voc = self.vocabulary[type]
i = random.randint(0, len(voc) - 1)
return voc[i]

def muc_online(self, presence):
"""Handles MUC online presence.
On bot connection gets called for each

Loading…
Cancel
Save