-
Notifications
You must be signed in to change notification settings - Fork 16
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
Topic feature #43
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.