-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvaDB.py
62 lines (41 loc) · 1.88 KB
/
EvaDB.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
from slack_sdk import WebClient
import ssl
import certifi
import evadb
SLACK_TOKEN = os.environ.get('SLACK_BOT_TOKEN')
CHANNEL_ID = "C05TGT8N1DL" #<<<<< CHANGE THIS TO THE CHANNEL YOU WANT THE BOT TO EXSIST ON
BOT_ID = "U05UCHLPD08" #<<<<< CHANAGE THIS TO YOUR BOT ID
# Setting up EvaDB and Slack API so we can see channel history
cursor = evadb.connect().cursor()
ssl_context = ssl.create_default_context(cafile=certifi.where())
client = WebClient(token=SLACK_TOKEN, ssl=ssl_context)
# get num messgaes from a spesific user
def getSingleUser(num, user, channel):
cursor.query("DROP DATABASE if exists slackTest;").execute()
cursor.query("""CREATE DATABASE slackTest WITH ENGINE = 'slack', PARAMETERS = {
"token": "{SLACK_TOKEN}",
"channel": "C05U262RF4H"};""").execute()
res = cursor.query(f"Select text, user from slackTest.{channel} where user = \"{user}\" LIMIT {num};").execute()
users = res.column_as_numpy_array("user")
mes = res.column_as_numpy_array("text")
Messagelist = ""
for m in range(len(mes)-1, -1 , -1):
x = f"{users[m]}: {mes[m]}"
Messagelist = Messagelist + x + "\n"
return Messagelist
# get num messgaes from a spesific user
def getGeneralMessages(num, channel):
cursor.query("DROP DATABASE if exists slackTest;").execute()
cursor.query("""CREATE DATABASE slackTest WITH ENGINE = 'slack', PARAMETERS = {
"token": "{SLACK_TOKEN}",
"channel": "C05U262RF4H"};""").execute()
res = cursor.query(f"Select text, user from slackTest.{channel} LIMIT {num};").execute()
users = res.column_as_numpy_array("user")
mes = res.column_as_numpy_array("text")
Messagelist = ""
for m in range(len(mes)-1, -1 , -1):
x = f"{users[m]}: {mes[m]}"
Messagelist = Messagelist + x + "\n"
return Messagelist
test = getGeneralMessages(10, "testingbot2")