Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
P
projet i2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Samy Haffoudhi
projet i2
Commits
7844bd7e
Commit
7844bd7e
authored
Dec 31, 2021
by
Samy Haffoudhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ajout des commandes cdp et gdp
parent
8c015961
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
app.py
bot/app.py
+50
-0
roles.json
bot/roles.json
+1
-0
No files found.
bot/app.py
100644 → 100755
View file @
7844bd7e
#!/bin/env python
import
os
from
slack_bolt
import
App
import
json
import
sys
FILENAME
=
'roles.json'
app
=
App
(
token
=
os
.
environ
.
get
(
"SLACK_BOT_TOKEN"
),
signing_secret
=
os
.
environ
.
get
(
"SLACK_SIGNING_SECRET"
)
)
def
update_roles
(
username
,
channel
,
role
):
with
open
(
FILENAME
,
'r'
)
as
f
:
try
:
roles
=
json
.
load
(
f
)
except
:
sys
.
exit
(
"La structure du fichier json est incorrecte !"
)
if
not
channel
in
roles
:
roles
[
channel
]
=
{}
roles
[
channel
][
role
]
=
username
with
open
(
FILENAME
,
'w'
)
as
f
:
json
.
dump
(
roles
,
f
)
def
define_rode
(
client
,
command
,
say
,
role
):
channel_id
=
command
[
'channel_id'
]
try
:
username
=
command
[
'text'
][
1
:]
except
:
username
=
command
[
'user_name'
]
users
=
client
.
users_list
()[
'members'
]
usernames
=
[
user
[
'name'
]
for
user
in
users
]
if
username
in
usernames
:
update_roles
(
username
,
channel_id
,
role
)
if
role
==
'cdp'
:
text
=
f
"<@{username}> est maintenant le chef de projet !"
else
:
text
=
f
"<@{username}> est maintenant le respo gestion de projet"
say
(
text
=
text
,
channel
=
channel_id
)
else
:
text
=
"Nom d'utilisateur non reconnu :confused:"
say
(
text
=
text
,
channel
=
channel_id
)
@
app
.
event
(
"channel_created"
)
def
join_channel
(
event
,
client
):
channel
=
event
[
'channel'
]
...
...
@@ -13,5 +53,15 @@ def join_channel(event, client):
client
.
conversations_join
(
channel
=
channel
[
'id'
])
client
.
chat_postMessage
(
channel
=
channel
[
'id'
],
text
=
"Salut !"
)
@
app
.
command
(
'/cdp'
)
def
define_cdp
(
ack
,
client
,
command
,
say
):
ack
()
define_rode
(
client
,
command
,
say
,
'cdp'
)
@
app
.
command
(
'/gdp'
)
def
define_cdp
(
ack
,
client
,
command
,
say
):
ack
()
define_rode
(
client
,
command
,
say
,
'gdp'
)
if
__name__
==
"__main__"
:
app
.
start
(
port
=
int
(
os
.
environ
.
get
(
"PORT"
,
3000
)))
bot/roles.json
0 → 100644
View file @
7844bd7e
{
"C02Q1HCCS2F"
:
{
"cdp"
:
"samy.haffoudhi195"
,
"gdp"
:
"projet_i2"
}}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment