Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
errbot-karma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IRC Team
Errbot Development
errbot-karma
Commits
36ff6dfc
Commit
36ff6dfc
authored
7 years ago
by
Bruce Cowan
Browse files
Options
Downloads
Patches
Plain Diff
Added postfix operators
Such as government-- and A350++
parent
b16ed391
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
karma.py
+28
-5
28 additions, 5 deletions
karma.py
with
28 additions
and
5 deletions
karma.py
+
28
−
5
View file @
36ff6dfc
# Copyright © 2016 Bruce Cowan <bruce@bcowan.eu>
# Copyright © 2016
, 2018
Bruce Cowan <bruce@bcowan.eu>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
...
...
@@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
collections
import
defaultdict
import
re
from
errbot
import
BotPlugin
,
botcmd
...
...
@@ -26,11 +27,35 @@ class Karma(BotPlugin):
self
.
karma
=
self
.
get
(
'
karma
'
,
defaultdict
(
int
))
self
.
inc
=
re
.
compile
(
r
'
(.+)\+\+
'
)
self
.
dec
=
re
.
compile
(
r
'
(.+)--
'
)
def
deactivate
(
self
):
self
[
'
karma
'
]
=
self
.
karma
super
().
deactivate
()
def
_inc_karma
(
self
,
target
,
message
):
self
.
karma
[
target
]
+=
1
text
=
"
Karma for
'
{}
'
is now {}
"
.
format
(
target
,
self
.
karma
[
target
])
self
.
send
(
message
.
to
,
text
,
message
,
True
)
def
_dec_karma
(
self
,
target
,
message
):
self
.
karma
[
target
]
-=
1
text
=
"
Karma for
'
{}
'
is now {}
"
.
format
(
target
,
self
.
karma
[
target
])
self
.
send
(
message
.
to
,
text
,
message
,
True
)
def
callback_message
(
self
,
message
):
# Increment?
match
=
self
.
inc
.
search
(
message
.
body
)
if
match
:
self
.
_inc_karma
(
match
.
group
(
1
),
message
)
# Decrement?
match
=
self
.
dec
.
search
(
message
.
body
)
if
match
:
self
.
_dec_karma
(
match
.
group
(
1
),
message
)
@botcmd
def
karma_list
(
self
,
message
,
args
):
"""
Prints a list of karmaed things
"""
...
...
@@ -46,8 +71,7 @@ class Karma(BotPlugin):
if
not
args
:
return
"
**Usage**: !karma add <target>
"
self
.
karma
[
args
]
+=
1
return
"
Karma for
'
{}
'
is now {}
"
.
format
(
args
,
self
.
karma
[
args
])
self
.
_inc_karma
(
args
,
message
)
@botcmd
def
karma_remove
(
self
,
message
,
args
):
...
...
@@ -55,8 +79,7 @@ class Karma(BotPlugin):
if
not
args
:
return
"
**Usage**: !karma remove <target>
"
self
.
karma
[
args
]
-=
1
return
"
Karma for
'
{}
'
is now {}
"
.
format
(
args
,
self
.
karma
[
args
])
self
.
_dec_karma
(
args
,
message
)
@botcmd
def
karma
(
self
,
message
,
args
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment