예제 #1
0
async def on_message(message):
	# log all messages
	#>>> CREATE TABLE logs (time real, channel text, id integer, name text, displayname text, messageid integer, deleted integer, edited integer, message text)
	sql_c.execute('INSERT INTO logs VALUES (?,?,?,?,?,?,?,?,?)', (message.timestamp.timestamp(), message.channel.name, int(message.author.id), message.author.name, message.author.display_name, int(message.id), 0, 0, str(message.content)))
	sql.commit()

	if not message.content.startswith('\\') and not message.author.id == client.user.id:
		# buffer words to the users
		'''markov.buffer_words(message.author.name, remove_urls(message.content))
		markov.buffer_words(client.user.name, remove_urls(message.content))

		if message.author.name != markov.last_speaker:
			markov.add_words(markov.last_speaker)
			markov.add_words(client.user.name)

		markov.last_speaker = message.author.name'''
		markov.add_line(message.channel.name, message.author.name, message.content)

	command_was_executed = False

	if message.content.startswith('\\') and len(message.content) > 1 and message.author.id != client.user.id:
		command_candidates = sorted([x.group() for x in [re.match(opt.replace('\\', '\\\\'), message.content[1:]) for opt in list(commander.keys())] if x], key=lambda x:len(x), reverse=True)
		if command_candidates:
			command = commander[command_candidates[0]]
			if not 'perms' in command or int(message.author.id) in command['perms']:
				command_was_executed = True

				if not message.author.id in banned_ids:
					await command['run'](message)

				else:
					banned_counter[0] += 1
					if banned_counter[0] > 10:
						banned_counter[0] = 0
						await client.send_message(message.channel, 'Stop it.')


	# regular message processing

	# check if there is a tell for the sender
	if message.author.id in tells:
		for item in tells[message.author.id]:
			await client.send_message(message.channel, '<@%s> %s (from <@%s>)' % (message.author.id, item['message'], item['senderid']))
		del tells[message.author.id]
		save_tells()

	# complain when someone tries to use \\ but only uses one backslash
	if message.content.startswith('\\'):
		if not command_was_executed and message.content[1:] in [x for x in list(reactions.keys()) if len(reactions[x]) > 0]:
			await client.send_message(message.channel, 'It\'s two backslashes, %s' % sailor_word())

	# complain when someone uses / insteand of \ to call a command
	if message.content.startswith('/'):
		if message.content[1:].split(' ')[0] in commander.keys():
			await client.send_message(message.channel, 'It\'s a backslash, %s' % sailor_word())
예제 #2
0
async def view_list(message):
	if not message.author.id in userlists:
		return

	listname = message.content.split(' ')[1]
	if not listname in userlists[message.author.id]:
		await client.send_message(message.channel, 'This list doesn\'t exist, %s' % sailor_word())

	await client.send_message(message.channel, '\n'.join( [str(k) + ' ' + v for k,v in enumerate(userlists[message.author.id][listname])] ))
예제 #3
0
async def change_voice_lang(message):
	if not ' ' in message.content:
		await client.send_message(message.channel, 'https://pastebin.com/QxdGXShe')
		return
	lang = message.content.split(' ')[1]
	if lang in gTTS.LANGUAGES:
		voice_wrapper.lang = lang
		await client.send_message(message.channel, 'Selected %s, %s' % (lang, gTTS.LANGUAGES[lang]))
	else:
		await client.send_message(message.channel, 'Not a language, %s' % sailor_word())
예제 #4
0
async def voice_say(message):
	if not voice_wrapper.voice:
		await client.send_message(message.channel, 'Run \\voice first, %s' % sailor_word())
		return
	if voice_wrapper.is_ready:
		voice_wrapper.is_ready = False
		tts = gTTS(message.content[5:], lang=voice_wrapper.lang)
		tts.save('voice.wav')
		voice_wrapper.player = voice_wrapper.voice.create_ffmpeg_player('voice.wav', after=voice_wrapper.after)
		voice_wrapper.streaming_media = False
		voice_wrapper.player.start()
예제 #5
0
async def voice_pop_queue(message):
	try:
		index = int(message.content.split(' ')[1])
		if index < 1:
			await client.send_message(message.channel, 'Cannot pop from the top of the list %s. Try `\\skip`.' % sailor_word())
			return

		if index >= len(voice_wrapper.queue):
			await client.send_message(message.channel, 'Your number is too big %s.' % sailor_word())
			return

		value = voice_wrapper.queue[index]
		del voice_wrapper.queue[index]

		await client.send_message(message.channel, 'Removed `%s` from the queue.' % (value[0] if type(value) == tuple else value))

	except ValueError:
		await client.send_message(message.channel, 'Needs to be a number, %s. Try `\\queue`.' % sailor_word())
예제 #6
0
async def listpop(message):
	if not message.author.id in userlists:
		return

	listname = message.content.split(' ')[1]
	if not listname in userlists[message.author.id]:
		await client.send_message(message.channel, 'This list doesn\'t exist, %s' % sailor_word())

	element = int(message.content.split(' ')[2])
	if element >= len(userlists[message.author.id]):
		return

	userlists[message.author.id][listname].pop(element)

	with open('userlists.json','w') as f:
		json.dump(userlists, f)

	await client.send_message(message.channel, 'Popped!')
예제 #7
0
async def voice_play_cached(message):
	if not voice_wrapper.voice:
		await client.send_message(message.channel, 'Run \\voice first, %s' % sailor_word())
		return
	files_sorted = await search_songs(message, message.content[6:])

	if len(files_sorted) > 0:
		voice_wrapper.queue.append( (files_sorted[0], 'cache') )
		messages_to_delete.append({
			'time': time.time() + 5.0,
			'message': await client.send_message(message.channel, 'Queueing %s in position %i' % (files_sorted[0], len(voice_wrapper.queue)-1))
		})
	else:
		return

	if voice_wrapper.is_ready:
		voice_wrapper.is_ready = False

		if not voice_wrapper.player or not voice_wrapper.player.is_playing():
			await voice_wrapper.play_next(message.channel)
예제 #8
0
async def voice_play_youtube(message):
	if not voice_wrapper.voice:
		await client.send_message(message.channel, 'Run \\voice first, %s' % sailor_word())
		return

	query = message.content[6:]
	if len(query) < 3:
		await client.send_message(message.channel, 'Query is too short.')
		return

	voice_wrapper.queue.append(query)
	messages_to_delete.append({
		'time': time.time() + 3.0,
		'message': await client.send_message(message.channel, 'Added to queue in position %i' % (len(voice_wrapper.queue)-1))
	})

	if voice_wrapper.is_ready:
		voice_wrapper.is_ready = False

		if not voice_wrapper.player or not voice_wrapper.player.is_playing():
			await voice_wrapper.play_next(message.channel)
예제 #9
0
async def voice_request(message):
	# Command behaviour: Join the caller's voice channel if in a voice channel.
	#  Leave the caller's voice channel if already in caller's voice channel.
	#  Move to the caller's voice channel if already in a different voice channel.

	if not voice_wrapper.voice:
		if not message.author.voice.voice_channel:
			await client.send_message(message.channel, 'You must join a voice channel first, %s' % sailor_word())
		else:
			voice_wrapper.voice = await client.join_voice_channel( message.author.voice.voice_channel )
			voice_wrapper.is_ready = True
	else:
		if voice_wrapper.voice.channel == message.author.voice.voice_channel:
			voice_wrapper.streaming_media = False
			await voice_wrapper.voice.disconnect()
			voice_wrapper.voice = None
		else:
			await voice_wrapper.voice.move_to( message.author.voice.voice_channel )