-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
Add tracking of users and their accounts #961
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ea7f144
Add tracking of users and their accounts
embolalia 24a6fe3
Address comments on PR #961
embolalia 54824f0
Add user tracking for RFC WHO replies
embolalia c2a0b17
Add away tracking
embolalia 729ee59
Add support for account-tag
embolalia 8f7af2a
Enable the account-tag capability
embolalia f179874
Replace channels list with channels dictionary
embolalia 941ec2b
Add cap-notify support
embolalia 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
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,64 @@ | ||
# coding=utf-8 | ||
from __future__ import unicode_literals, absolute_import, print_function, division | ||
|
||
import functools | ||
from sopel.tools import Identifier | ||
|
||
|
||
@functools.total_ordering | ||
class User(object): | ||
def __init__(self, nick, user, host): | ||
assert isinstance(nick, Identifier) | ||
self.nick = nick | ||
self.user = user | ||
self.host = host | ||
self.channels = {} | ||
|
||
hostmask = property(lambda self: '{}!{}@{}'.format(self.nick, self.user, | ||
self.host)) | ||
|
||
def __eq__(self, other): | ||
if not isinstance(other, User): | ||
return NotImplemented | ||
return self.name == other.name | ||
|
||
def __lt__(self, other): | ||
if not isinstance(other, User): | ||
return NotImplemented | ||
return self.name < other.name | ||
|
||
|
||
@functools.total_ordering | ||
class Channel(object): | ||
def __init__(self, name): | ||
assert isinstance(name, Identifier) | ||
self.name = name | ||
self.users = {} | ||
self.privileges = {} | ||
|
||
def clear_user(self, nick): | ||
user = self.users[nick] | ||
user.channels.pop(self.name, None) | ||
del self.users[nick] | ||
del self.privileges[nick] | ||
|
||
def add_user(self, user): | ||
assert isinstance(user, User) | ||
self.users[user.nick] = user | ||
self.privileges[user.nick] = 0 | ||
|
||
def rename_user(self, old, new): | ||
if old in self.users: | ||
self.users[new] = self.users.pop(old) | ||
if old in self.privileges: | ||
self.privileges[new] = self.privileges.pop(old) | ||
|
||
def __eq__(self, other): | ||
if not isinstance(other, Channel): | ||
return NotImplemented | ||
return self.name == other.name | ||
|
||
def __lt__(self, other): | ||
if not isinstance(other, Channel): | ||
return NotImplemented | ||
return self.name < other.name |
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.
name is not defined for user, same thing on line 28