9
9
import os
10
10
from random import choice
11
11
import asyncio
12
+ import json
12
13
13
14
last = None
14
15
15
- bot = commands .Bot (command_prefix = ['clip!' , 'c!' ])
16
+ try :
17
+ with open ('../sentence_mapper.json' , 'r' ) as f :
18
+ sentence_mapper = json .load (f )
19
+ except :
20
+ print ('Please create sentence_mapper.json' )
21
+ exit ()
22
+
23
+
24
+ bot = commands .Bot (command_prefix = ['clip!' , 'c!' , '?' ])
16
25
17
26
@bot .event
18
27
async def on_ready ():
@@ -26,14 +35,17 @@ async def play(ctx, *args):
26
35
if ctx .author .voice is None :
27
36
print ("Connect to voice, idiot." )
28
37
return
29
- file = '../clips/' + args [0 ] + '.mp3'
38
+ if args [0 ] not in sentence_mapper .keys ():
39
+ print ("No this sentence in sentence_mapper" )
40
+ await ctx .reply ("Not this sentence in list" )
41
+ return
42
+ file = '../clips/' + sentence_mapper [args [0 ]]
30
43
if not path .exists (file ):
31
- print (os .getcwd ())
32
44
print ("No such file (" + args [0 ] + ".mp3)" )
33
45
await ctx .reply (args [0 ] + " does not exists." )
34
46
return
35
47
global last
36
- last = args [0 ]
48
+ last = sentence_mapper [ args [0 ] ]
37
49
user_channel = ctx .author .voice .channel
38
50
39
51
voice_client = None
@@ -50,6 +62,11 @@ async def play(ctx, *args):
50
62
except AttributeError :
51
63
pass
52
64
65
+ @bot .command (aliases = ["ls" ])
66
+ async def get_existing_sentences (ctx ):
67
+ global sentence_mapper
68
+ await ctx .reply ("```python\n Existing sentences\n {}```" .format ('\n ' .join ([sentence .strip () for sentence in sentence_mapper .keys ()])))
69
+
53
70
@bot .command (aliases = ["r" ])
54
71
async def random (ctx ):
55
72
r = choice (listdir ("../clips" ))
0 commit comments