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
f0b59c71
Commit
f0b59c71
authored
3 years ago
by
Bruce Cowan
Browse files
Options
Downloads
Patches
Plain Diff
Add karma delete thingy
parent
5f598c11
No related branches found
No related tags found
1 merge request
!4
Complete rewrite
Pipeline
#3018
passed
3 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
karma.py
+18
-6
18 additions, 6 deletions
karma.py
with
18 additions
and
6 deletions
karma.py
+
18
−
6
View file @
f0b59c71
...
...
@@ -2,9 +2,10 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
from
__future__
import
annotations
import
collections
import
re
from
typing
import
Optional
import
errbot
...
...
@@ -30,7 +31,7 @@ class Karma(errbot.BotPlugin):
return
f
"
Karma for
'
{
target
}
'
is now
{
self
[
'
karma
'
][
target
]
}
"
@errbot.re_botcmd
(
pattern
=
r
"
(.+)\+\+
"
,
prefixed
=
False
,
flags
=
re
.
IGNORECASE
)
def
on_karma_inc
(
self
,
message
:
errbot
.
Message
,
match
:
re
.
Match
)
->
Optional
[
str
]
:
def
on_karma_inc
(
self
,
message
:
errbot
.
Message
,
match
:
re
.
Match
)
->
str
|
None
:
"""
Adds karma
"""
if
message
.
frm
==
self
.
bot_identifier
:
return
...
...
@@ -40,7 +41,7 @@ class Karma(errbot.BotPlugin):
return
self
.
_change_karma
(
match
.
group
(
1
),
1
)
@errbot.re_botcmd
(
pattern
=
r
"
(.+)--
"
,
prefixed
=
False
,
flags
=
re
.
IGNORECASE
)
def
on_karma_dec
(
self
,
message
:
errbot
.
Message
,
match
:
re
.
Match
)
->
Optional
[
str
]
:
def
on_karma_dec
(
self
,
message
:
errbot
.
Message
,
match
:
re
.
Match
)
->
str
|
None
:
"""
Removes karma
"""
if
message
.
frm
==
self
.
bot_identifier
:
return
...
...
@@ -48,7 +49,7 @@ class Karma(errbot.BotPlugin):
return
self
.
_change_karma
(
match
.
group
(
1
),
-
1
)
@errbot.botcmd
def
karma
(
self
,
message
:
errbot
.
Message
,
args
:
Optional
[
str
]
)
->
str
:
def
karma
(
self
,
message
:
errbot
.
Message
,
args
:
str
|
None
)
->
str
:
"""
Gets karma
"""
if
not
args
:
return
"
**Usage**: !karma <target>
"
...
...
@@ -56,7 +57,7 @@ class Karma(errbot.BotPlugin):
return
f
"
Karma for
'
{
args
}
'
is
{
self
[
'
karma
'
][
args
]
}
"
@errbot.botcmd
def
karma_top
(
self
,
message
:
errbot
.
Message
,
args
:
Optional
[
str
]
)
->
str
:
def
karma_top
(
self
,
message
:
errbot
.
Message
,
args
:
str
|
None
)
->
str
:
"""
Gets the top n items
"""
if
len
(
self
[
"
karma
"
])
==
0
:
return
"
There are no items with karma
"
...
...
@@ -70,7 +71,7 @@ class Karma(errbot.BotPlugin):
return
"
,
"
.
join
([
f
"
{
k
}
:
{
v
}
"
for
k
,
v
in
top
])
@errbot.botcmd
def
karma_bottom
(
self
,
message
:
errbot
.
Message
,
args
:
Optional
[
str
]
)
->
str
:
def
karma_bottom
(
self
,
message
:
errbot
.
Message
,
args
:
str
|
None
)
->
str
:
"""
Gets the bottom n items
"""
if
len
(
self
[
"
karma
"
])
==
0
:
return
"
There are no items with karma
"
...
...
@@ -82,3 +83,14 @@ class Karma(errbot.BotPlugin):
bottom
=
self
[
"
karma
"
].
most_common
()[:
-
num
-
1
:
-
1
]
return
"
,
"
.
join
([
f
"
{
k
}
:
{
v
}
"
for
k
,
v
in
bottom
])
@errbot.botcmd
def
karma_reset
(
self
,
message
:
errbot
.
Message
,
args
:
str
|
None
)
->
str
:
args
=
args
.
strip
()
if
args
not
in
self
[
"
karma
"
]:
return
"
**Error**: no such item
"
with
self
.
mutable
(
"
karma
"
)
as
k
:
del
k
[
args
]
return
f
"
Deleted
{
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