Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
strolchibot
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
dnns01
strolchibot
Commits
78a20875
Commit
78a20875
authored
2 years ago
by
dnns01
Browse files
Options
Downloads
Patches
Plain Diff
Added possibility for argument related chat commands (like !so)
parent
bf483fae
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
twitchbot/chat_commands.py
+21
-6
21 additions, 6 deletions
twitchbot/chat_commands.py
with
22 additions
and
6 deletions
.gitignore
+
1
−
0
View file @
78a20875
...
@@ -119,3 +119,4 @@ GitHub.sublime-settings
...
@@ -119,3 +119,4 @@ GitHub.sublime-settings
/spotify.json
/spotify.json
/clips/
/clips/
.idea/sonarlint/
.idea/sonarlint/
/einkaufsliste.json
This diff is collapsed.
Click to expand it.
twitchbot/chat_commands.py
+
21
−
6
View file @
78a20875
...
@@ -7,6 +7,8 @@ from twitchio.ext import commands
...
@@ -7,6 +7,8 @@ from twitchio.ext import commands
import
spotify_cog
import
spotify_cog
import
config
import
config
DB_PATH
=
"
db.sqlite3
"
class
Commands
(
commands
.
Cog
):
class
Commands
(
commands
.
Cog
):
def
__init__
(
self
,
bot
):
def
__init__
(
self
,
bot
):
...
@@ -22,7 +24,7 @@ class Commands(commands.Cog):
...
@@ -22,7 +24,7 @@ class Commands(commands.Cog):
command
=
msg
[
0
][
1
:]
command
=
msg
[
0
][
1
:]
args
=
msg
[
1
:]
args
=
msg
[
1
:]
conn
=
sqlite3
.
connect
(
"
db.sqlite3
"
)
conn
=
sqlite3
.
connect
(
DB_PATH
)
c
=
conn
.
cursor
()
c
=
conn
.
cursor
()
c
.
execute
(
'
SELECT text from strolchibot_command where command = ? and active is true
'
,
(
command
,))
c
.
execute
(
'
SELECT text from strolchibot_command where command = ? and active is true
'
,
(
command
,))
...
@@ -39,7 +41,6 @@ class Commands(commands.Cog):
...
@@ -39,7 +41,6 @@ class Commands(commands.Cog):
for
variable
in
variables
:
for
variable
in
variables
:
tokens
=
variable
[
1
:
-
1
].
split
()
tokens
=
variable
[
1
:
-
1
].
split
()
print
(
tokens
[
4
:])
if
tokens
[
0
]
==
"
count
"
or
tokens
[
0
]
==
"
getcount
"
:
if
tokens
[
0
]
==
"
count
"
or
tokens
[
0
]
==
"
getcount
"
:
count
=
self
.
process_counter
(
tokens
[
0
],
tokens
[
1
:])
count
=
self
.
process_counter
(
tokens
[
0
],
tokens
[
1
:])
text
=
text
.
replace
(
variable
,
str
(
count
))
text
=
text
.
replace
(
variable
,
str
(
count
))
...
@@ -52,7 +53,10 @@ class Commands(commands.Cog):
...
@@ -52,7 +53,10 @@ class Commands(commands.Cog):
streamer
=
self
.
process_streamer
()
streamer
=
self
.
process_streamer
()
if
streamer
:
if
streamer
:
text
=
text
.
replace
(
variable
,
streamer
.
capitalize
())
text
=
text
.
replace
(
variable
,
streamer
.
capitalize
())
elif
tokens
[
0
]
==
"
args
"
and
len
(
tokens
)
==
2
:
arg
=
self
.
process_args
(
args
,
tokens
[
1
])
if
arg
:
text
=
text
.
replace
(
variable
,
arg
)
return
text
return
text
def
process_counter
(
self
,
var_name
,
params
):
def
process_counter
(
self
,
var_name
,
params
):
...
@@ -75,7 +79,7 @@ class Commands(commands.Cog):
...
@@ -75,7 +79,7 @@ class Commands(commands.Cog):
return
counter
return
counter
def
get_count
(
self
,
name
):
def
get_count
(
self
,
name
):
conn
=
sqlite3
.
connect
(
"
db.sqlite3
"
)
conn
=
sqlite3
.
connect
(
DB_PATH
)
c
=
conn
.
cursor
()
c
=
conn
.
cursor
()
c
.
execute
(
'
SELECT count from strolchibot_counter where name = ?
'
,
(
name
,))
c
.
execute
(
'
SELECT count from strolchibot_counter where name = ?
'
,
(
name
,))
count
=
c
.
fetchone
()
count
=
c
.
fetchone
()
...
@@ -83,7 +87,7 @@ class Commands(commands.Cog):
...
@@ -83,7 +87,7 @@ class Commands(commands.Cog):
if
count
:
if
count
:
return
count
[
0
]
return
count
[
0
]
else
:
else
:
conn
=
sqlite3
.
connect
(
"
db.sqlite3
"
)
conn
=
sqlite3
.
connect
(
DB_PATH
)
c
=
conn
.
cursor
()
c
=
conn
.
cursor
()
c
.
execute
(
'
INSERT INTO strolchibot_counter(name, count) VALUES (?, ?)
'
,
(
name
,
0
))
c
.
execute
(
'
INSERT INTO strolchibot_counter(name, count) VALUES (?, ?)
'
,
(
name
,
0
))
conn
.
commit
()
conn
.
commit
()
...
@@ -91,7 +95,7 @@ class Commands(commands.Cog):
...
@@ -91,7 +95,7 @@ class Commands(commands.Cog):
return
0
return
0
def
set_count
(
self
,
name
,
count
):
def
set_count
(
self
,
name
,
count
):
conn
=
sqlite3
.
connect
(
"
db.sqlite3
"
)
conn
=
sqlite3
.
connect
(
DB_PATH
)
c
=
conn
.
cursor
()
c
=
conn
.
cursor
()
c
.
execute
(
'
UPDATE strolchibot_counter set count = ? where name = ?
'
,
(
count
,
name
))
c
.
execute
(
'
UPDATE strolchibot_counter set count = ? where name = ?
'
,
(
count
,
name
))
conn
.
commit
()
conn
.
commit
()
...
@@ -111,3 +115,14 @@ class Commands(commands.Cog):
...
@@ -111,3 +115,14 @@ class Commands(commands.Cog):
def
process_streamer
(
self
):
def
process_streamer
(
self
):
return
config
.
get
(
"
streamer
"
)
return
config
.
get
(
"
streamer
"
)
def
process_args
(
self
,
args
,
index
):
try
:
index
=
int
(
index
)
except
ValueError
:
index
=
0
if
len
(
args
)
>
index
:
return
args
[
0
]
return
None
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