Spaces:
Paused
Paused
2 big updates: individual threads for daily pings + multiple recognizable trigger words per message
Browse files
app.py
CHANGED
|
@@ -28,17 +28,40 @@ ARGILLA_HELP_CHANNEL_ID = 1253640751481356330
|
|
| 28 |
DATA_DISCUSSIONS_CHANNEL_ID = 1217179426002047076
|
| 29 |
|
| 30 |
|
| 31 |
-
# U051DB2754M == adam hf real slack
|
| 32 |
-
# U061W3NRFFA == lunarflu test slack
|
| 33 |
-
|
| 34 |
TRIGGERS = {
|
| 35 |
("discord bot",): "<@U051DB2754M>", # adam
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
|
| 41 |
-
|
| 42 |
daily_pings = []
|
| 43 |
|
| 44 |
intents = discord.Intents.all()
|
|
@@ -65,23 +88,23 @@ async def on_message(message):
|
|
| 65 |
|
| 66 |
huggingfolks_role = discord.utils.get(message.guild.roles, id=897376942817419265)
|
| 67 |
bots_role = discord.utils.get(message.guild.roles, id=1258328471609016341)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
|
| 86 |
# Check if the message is in a thread
|
| 87 |
if isinstance(message.channel, discord.Thread):
|
|
@@ -219,7 +242,7 @@ def send_daily_pings():
|
|
| 219 |
print(f"sending daily pings...{daily_pings}")
|
| 220 |
pings_by_mention = {}
|
| 221 |
|
| 222 |
-
# group pings by
|
| 223 |
for ping in daily_pings:
|
| 224 |
mention = ping['mention']
|
| 225 |
if mention not in pings_by_mention:
|
|
@@ -229,7 +252,7 @@ def send_daily_pings():
|
|
| 229 |
# send each group of pings in a separate thread
|
| 230 |
for mention, pings in pings_by_mention.items():
|
| 231 |
main_message = slack_client.chat_postMessage(
|
| 232 |
-
channel=
|
| 233 |
text=f"DAILY PINGS FOR {mention} ON {datetime.now().strftime('%d/%m/%Y')}",
|
| 234 |
unfurl_links=False,
|
| 235 |
unfurl_media=False
|
|
@@ -237,7 +260,7 @@ def send_daily_pings():
|
|
| 237 |
main_ts = main_message['ts']
|
| 238 |
for ping in pings:
|
| 239 |
slack_client.chat_postMessage(
|
| 240 |
-
channel=
|
| 241 |
text=f"{ping['mention']} (for the keyword -> '{ping['trigger']}')\nFrom {ping['author']} in channel #{ping['channel']}: {ping['content']}\n{ping['url']}",
|
| 242 |
thread_ts=main_ts,
|
| 243 |
unfurl_links=False,
|
|
@@ -249,7 +272,7 @@ def send_daily_pings():
|
|
| 249 |
# pings -------------------------------------------------------------------------------------------
|
| 250 |
executor = ThreadPoolExecutor(max_workers=1)
|
| 251 |
scheduler = BackgroundScheduler(executors={'default': executor})
|
| 252 |
-
scheduler.add_job(send_daily_pings, trigger='interval',
|
| 253 |
scheduler.start()
|
| 254 |
|
| 255 |
|
|
@@ -260,4 +283,4 @@ threading.Thread(target=run_bot).start()
|
|
| 260 |
def greet(name):
|
| 261 |
return "Hello " + name + "!"
|
| 262 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 263 |
-
demo.launch()
|
|
|
|
| 28 |
DATA_DISCUSSIONS_CHANNEL_ID = 1217179426002047076
|
| 29 |
|
| 30 |
|
|
|
|
|
|
|
|
|
|
| 31 |
TRIGGERS = {
|
| 32 |
("discord bot",): "<@U051DB2754M>", # adam
|
| 33 |
+
("autotrain",): "<@U01E3LEC2N7>", # abhishek
|
| 34 |
+
("auto train",): "<@U01E3LEC2N7>", # abhishek
|
| 35 |
+
("competition",): "<@U01E3LEC2N7>", # abhishek
|
| 36 |
+
("competitions",): "<@U01E3LEC2N7>", # abhishek
|
| 37 |
+
("text to speech",): "<@U039C2GANMV>", # VB
|
| 38 |
+
("tts",): "<@U039C2GANMV>", # VB
|
| 39 |
+
("asr",): "<@U039C2GANMV>", # VB
|
| 40 |
+
("musicgen",): "<@U039C2GANMV>", # VB
|
| 41 |
+
("whisper",): "<@U039C2GANMV>", # VB
|
| 42 |
+
("speech recognition",): "<@U039C2GANMV>", # VB
|
| 43 |
+
("bark",): "<@U039C2GANMV>", # VB
|
| 44 |
+
("sentence-transformers",): "<@U04E4DNPWG7>", # tom aarsen
|
| 45 |
+
("sentence_transformers",): "<@U04E4DNPWG7>", # tom aarsen
|
| 46 |
+
("setfit",): "<@U04E4DNPWG7>", # tom aarsen
|
| 47 |
+
("sentence transformers",): "<@U04E4DNPWG7>", # tom aarsen
|
| 48 |
+
("argilla",): "<@U076B8C7G3E>", # david berenstein
|
| 49 |
+
("distilabel",): "<@U076B8C7G3E>", # david berenstein
|
| 50 |
+
("argilla",): "<@U0766H30T7F>", # natalia elvira
|
| 51 |
+
("dataset",): "<@U0766H30T7F>", # natalia elvira
|
| 52 |
+
("docs",): "<@U02DATT4C5B>", # steven liu
|
| 53 |
+
("documentation",): "<@U02DATT4C5B>", # steven liu
|
| 54 |
+
("gradio",): "<@U02NMK75F1V>", # abubakar abid
|
| 55 |
+
("gradio",): "<@U04FLGQ26PQ>", # yuvraj sharma
|
| 56 |
+
("argilla",): "<@U076MF65WEM>", # sara han diaz lorenzo
|
| 57 |
+
("distilabel",): "<@U076MF65WEM>", # sara han diaz lorenzo
|
| 58 |
+
("argilla",): "<@U0765RENPNZ>", # sara han diaz lorenzo
|
| 59 |
+
("distilabel",): "<@U0765RENPNZ>", # sara han diaz lorenzo
|
| 60 |
+
("dataset", "feedback"): "<@U0768RCHCRY>", # ben burtenshaw
|
| 61 |
+
("distilabel",): "<@U0768QEN0LA>", # Gabriel Martín Blázquez
|
| 62 |
+
("distilabel",): "<@U076271MBUN>", # Agustín Piqueres
|
| 63 |
}
|
| 64 |
|
|
|
|
| 65 |
daily_pings = []
|
| 66 |
|
| 67 |
intents = discord.Intents.all()
|
|
|
|
| 88 |
|
| 89 |
huggingfolks_role = discord.utils.get(message.guild.roles, id=897376942817419265)
|
| 90 |
bots_role = discord.utils.get(message.guild.roles, id=1258328471609016341)
|
| 91 |
+
if huggingfolks_role not in message.author.roles: # no need for ping if we're already discussing
|
| 92 |
+
if bots_role not in message.author.roles: # bots shouldn't trigger pings for this
|
| 93 |
+
print(" not bot ")
|
| 94 |
+
content = message.content.lower()
|
| 95 |
+
|
| 96 |
+
for trigger, slack_mention in TRIGGERS.items():
|
| 97 |
+
if all(word in content for word in trigger):
|
| 98 |
+
adjacent_words = extract_adjacent_words(message.content, trigger)
|
| 99 |
+
daily_pings.append({
|
| 100 |
+
'author': str(message.author),
|
| 101 |
+
'content': adjacent_words,
|
| 102 |
+
'channel': message.channel.name,
|
| 103 |
+
'url': message.jump_url,
|
| 104 |
+
'mention': slack_mention,
|
| 105 |
+
'trigger': trigger
|
| 106 |
+
})
|
| 107 |
+
print(f"daily pings:{daily_pings}")
|
| 108 |
|
| 109 |
# Check if the message is in a thread
|
| 110 |
if isinstance(message.channel, discord.Thread):
|
|
|
|
| 242 |
print(f"sending daily pings...{daily_pings}")
|
| 243 |
pings_by_mention = {}
|
| 244 |
|
| 245 |
+
# group pings by who they are meant to notify
|
| 246 |
for ping in daily_pings:
|
| 247 |
mention = ping['mention']
|
| 248 |
if mention not in pings_by_mention:
|
|
|
|
| 252 |
# send each group of pings in a separate thread
|
| 253 |
for mention, pings in pings_by_mention.items():
|
| 254 |
main_message = slack_client.chat_postMessage(
|
| 255 |
+
channel=SLACK_CHANNEL_ID,
|
| 256 |
text=f"DAILY PINGS FOR {mention} ON {datetime.now().strftime('%d/%m/%Y')}",
|
| 257 |
unfurl_links=False,
|
| 258 |
unfurl_media=False
|
|
|
|
| 260 |
main_ts = main_message['ts']
|
| 261 |
for ping in pings:
|
| 262 |
slack_client.chat_postMessage(
|
| 263 |
+
channel=SLACK_CHANNEL_ID,
|
| 264 |
text=f"{ping['mention']} (for the keyword -> '{ping['trigger']}')\nFrom {ping['author']} in channel #{ping['channel']}: {ping['content']}\n{ping['url']}",
|
| 265 |
thread_ts=main_ts,
|
| 266 |
unfurl_links=False,
|
|
|
|
| 272 |
# pings -------------------------------------------------------------------------------------------
|
| 273 |
executor = ThreadPoolExecutor(max_workers=1)
|
| 274 |
scheduler = BackgroundScheduler(executors={'default': executor})
|
| 275 |
+
scheduler.add_job(send_daily_pings, trigger='interval', days=1)
|
| 276 |
scheduler.start()
|
| 277 |
|
| 278 |
|
|
|
|
| 283 |
def greet(name):
|
| 284 |
return "Hello " + name + "!"
|
| 285 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 286 |
+
demo.launch()
|