| Total Complexity | 9 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | try: |
||
| 8 | class YTH(BaseModule): |
||
| 9 | def post_init(self): |
||
| 10 | command = Event("__.yth__") |
||
| 11 | command.define(msg_definition="^\.yth") |
||
| 12 | command.subscribe(self) |
||
| 13 | |||
| 14 | self.bot.register_event(command, self) |
||
| 15 | self.help = ".yth, .yth <search terms>" |
||
| 16 | self.comparer = difflib.SequenceMatcher() |
||
| 17 | |||
| 18 | def handle(self, event): |
||
| 19 | if len(event.msg.split()) == 1: |
||
| 20 | count = 0 |
||
| 21 | msg = list() |
||
| 22 | while count < 5 and count < len(self.bot.mem_store['youtube']): |
||
| 23 | for entry, url in reversed(self.bot.mem_store['youtube'].items()): |
||
| 24 | msg.append(entry + " - " + url) |
||
| 25 | count += 1 |
||
| 26 | self.say(event.user, ", ".join(msg)) |
||
| 27 | elif len(event.msg.split()) > 1: # we're searching for specific terms |
||
| 28 | terms = event.msg.split()[1:-1] # terms from 1 (ignore .yth) to the end |
||
| 29 | msg = list() |
||
| 30 | for k, v in self.bot.mem_store['youtube'].items(): |
||
| 31 | self.comparer.set_seq1(k.lower()) |
||
| 32 | self.comparer.set_seq2(" ".join(terms)) |
||
| 33 | if self.comparer.ratio() >= .75: |
||
| 34 | msg.append(k + " - " + v) |
||
| 35 | |||
| 36 | self.say(event.user, ", ".join(msg)) |
||
| 37 |