Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topic feature #43

Merged
merged 4 commits into from
Oct 23, 2013
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions csbot.example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@
# This configuration is for the Example plugin
[example]
foo = bar

[topic]
separator = |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth switching this to '::' as that's what we seem to use atm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's configuration... after all... dev uses | that's what i used for dev/test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but I think the example config is meant to be close to the real config. Might be worth checking with @alanbriolat ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, cmon Haegin, this is not a big deal :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but it's also a 2 second fix. I don't mind making the fix later if
necessary. I was just doing a 'review ALL the csbot pull requests' thing.

Regards,
Harry Mills
http://haeg.in
07708228571

On 4 December 2012 20:07, Andrei [email protected] wrote:

In csbot.example.cfg:

@@ -48,3 +48,7 @@

This configuration is for the Example plugin

[example]
foo = bar
+
+[topic]
+separator = |

Oh, cmon Haegin, this is not a big deal :D


Reply to this email directly or view it on GitHubhttps://github.com//pull/43/files#r2311797.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example should reflect the defaults that are used in absence of a configuration. csbot.deploy.cfg is the configuration that the deployed bot uses.

users = Haegin Alan DinCahill hayashi
84 changes: 84 additions & 0 deletions csbot/plugins/topic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import requests
import urllib

from csbot.plugin import Plugin
from csbot.util import nick

class TopicException(Exception):
pass

class Topic(Plugin):

def setup(self):
super(Topic, self).setup()
self.topic = {}


@Plugin.hook('core.channel.topic')
def currentTopic(self, e):
self.topics[e["channel"]] = e['topic']

@Plugin.command('topic')
def topic(self, e):
"""Manipulate the topic. Possible commands: add append prepend remove change.
"""
try:
if not nick(e['user']) in self.config_get("users").split(" "):
raise TopicException(u"You do not have permission to execute that command")

command, payload = e['data'].split(" ", 1)
separator = self.config_get("separator")

splitted_topic = self.topics[e["reply_to"]].split(" "+separator+" ")

position = None

#map append alias to add to last position
if command == "append":
command = "add"
position = len(splitted_topic)

#map prepend alias to add to first position
if command == "prepend":
command = "add"
position = 0

#handle the add comand
if command == "add":
if position is None:
position, payload = payload.split(" ", 1)

if not position.isdigit() or int(position) >= len(splitted_topic):
raise TopicException(u"Invalid position number")

position = int(position)

if position == len(splitted_topic):
splitted_topic.append(payload)
else:
splitted_topic.insert(position, payload)

#handle the remove command
elif command == "remove":
position = payload

if not position.isdigit() or int(position) >= len(splitted_topic):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional is used at least twice, would it be better to pull it out to a meaningfully named method?

raise TopicException(u"Invalid position number")

position = int(position)

del splitted_topic[position]
#handle the change command
elif command == "change":
position, payload = payload.split(" ", 1)

if not position.isdigit() or int(position) >= len(splitted_topic):
raise TopicException(u"Invalid position number")

position = int(position)

splitted_topic[position] = payload

e.protocol.topic(e["reply_to"], (" "+separator+" ").join(splitted_topic))
except TopicException as exception:
e.protocol.msg(e["reply_to"], "Topic error: " + str(exception))