xcx0902 commited on
Commit
88d4782
Β·
verified Β·
1 Parent(s): 675140f

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +29 -7
  2. requirements.txt +2 -1
app.py CHANGED
@@ -3,12 +3,17 @@ import json
3
  import os
4
  import requests
5
  import time
 
 
6
 
7
  intents = discord.Intents.default()
8
  intents.message_content = True
9
 
10
  client = discord.Client(intents=intents)
11
 
 
 
 
12
 
13
  @client.event
14
  async def on_ready():
@@ -20,20 +25,20 @@ async def on_message(message):
20
  print(f'{message.author}: {message.content}')
21
  if message.author == client.user:
22
  return
23
- if message.content == '.hello':
24
  await message.channel.send('Hello!')
25
- if message.content == '.time':
26
  await message.channel.send(time.asctime(time.localtime(time.time())) + ' UTC')
27
- if message.content == '.quote':
28
  api = "https://v1.hitokoto.cn/"
29
  response = requests.get(api)
30
  json_data = json.loads(response.text)
31
  await message.channel.send(json_data['hitokoto'] + ' β€”β€”' + json_data['from'])
32
- if message.content == '.florrmap':
33
  # map_url_old = 'https://raw.githubusercontents.com/xcx0902/images/main/florr/map-5.3.png'
34
  map_url = 'https://raw.githubusercontents.com/xcx0902/images/main/florr/map24-4.13.png'
35
  await message.channel.send(map_url)
36
- if message.content == '.florrserver':
37
  await message.channel.send('Try to get server info from api...')
38
  answer = ''
39
  mpname = {
@@ -58,7 +63,7 @@ async def on_message(message):
58
  'Try using the following code in the browser console to change the server:\n'
59
  '```javascript\ncp6.forceServerID(\'<serverid>\');\n```'
60
  )
61
- if message.content.startswith('.tetriouser'):
62
  username = message.content.split(' ')[1].lower()
63
  api = 'https://ch.tetr.io/api/users/' + username
64
  response = requests.get(api, headers={"User-Agent": "discord-bot"})
@@ -90,7 +95,7 @@ async def on_message(message):
90
  except BaseException:
91
  pass
92
  await message.channel.send('```' + answer + '```')
93
- if message.content == '.help':
94
  await message.channel.send(
95
  '.hello : Say hello to the bot (You will get a hello back)\n'
96
  '.time : Show the date and time now\n'
@@ -100,6 +105,23 @@ async def on_message(message):
100
  '.tetriouser <username> : Get tetr.io user info\n'
101
  '.help : Show this message'
102
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
 
105
  # print(os.getenv("TOKEN"))
 
3
  import os
4
  import requests
5
  import time
6
+ import openai
7
+ import random
8
 
9
  intents = discord.Intents.default()
10
  intents.message_content = True
11
 
12
  client = discord.Client(intents=intents)
13
 
14
+ config = json.loads(os.getenv("CONFIG"))
15
+ keys: list[str] = config["api_key"]
16
+
17
 
18
  @client.event
19
  async def on_ready():
 
25
  print(f'{message.author}: {message.content}')
26
  if message.author == client.user:
27
  return
28
+ elif message.content == '.hello':
29
  await message.channel.send('Hello!')
30
+ elif message.content == '.time':
31
  await message.channel.send(time.asctime(time.localtime(time.time())) + ' UTC')
32
+ elif message.content == '.quote':
33
  api = "https://v1.hitokoto.cn/"
34
  response = requests.get(api)
35
  json_data = json.loads(response.text)
36
  await message.channel.send(json_data['hitokoto'] + ' β€”β€”' + json_data['from'])
37
+ elif message.content == '.florrmap':
38
  # map_url_old = 'https://raw.githubusercontents.com/xcx0902/images/main/florr/map-5.3.png'
39
  map_url = 'https://raw.githubusercontents.com/xcx0902/images/main/florr/map24-4.13.png'
40
  await message.channel.send(map_url)
41
+ elif message.content == '.florrserver':
42
  await message.channel.send('Try to get server info from api...')
43
  answer = ''
44
  mpname = {
 
63
  'Try using the following code in the browser console to change the server:\n'
64
  '```javascript\ncp6.forceServerID(\'<serverid>\');\n```'
65
  )
66
+ elif message.content.startswith('.tetriouser'):
67
  username = message.content.split(' ')[1].lower()
68
  api = 'https://ch.tetr.io/api/users/' + username
69
  response = requests.get(api, headers={"User-Agent": "discord-bot"})
 
95
  except BaseException:
96
  pass
97
  await message.channel.send('```' + answer + '```')
98
+ elif message.content == '.help':
99
  await message.channel.send(
100
  '.hello : Say hello to the bot (You will get a hello back)\n'
101
  '.time : Show the date and time now\n'
 
105
  '.tetriouser <username> : Get tetr.io user info\n'
106
  '.help : Show this message'
107
  )
108
+ else:
109
+ key = random.choice(keys)
110
+ response = openai.OpenAI(
111
+ api_key=key,
112
+ base_url=config["url"],
113
+ default_headers={
114
+ "User-Agent": config.get("user_agent", ""),
115
+ "Cookie": config.get("cookie", "")
116
+ }
117
+ ).chat.completions.create(
118
+ model=config["model"],
119
+ messages=[
120
+ {"role": "user", "content": message.content}
121
+ ],
122
+ stream=False
123
+ ).choices[0].message.content
124
+ await message.channel.send(response)
125
 
126
 
127
  # print(os.getenv("TOKEN"))
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  discord
2
- requests
 
 
1
  discord
2
+ requests
3
+ openai