Created
December 12, 2017 15:35
-
-
Save bitmappergit/1e4480e2eeb0dd90d87d17e4ceaf87af to your computer and use it in GitHub Desktop.
bot.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "./haikubot/*" | |
require "../lib/sylcnt.cr" | |
require "../lib/discordcr/src/discordcr" | |
# TODO write explination of commands and code | |
module Haikubot | |
config = File.read_lines("./haiku.conf") | |
puts config[0] | |
client = Discord::Client.new(token: "Bot " + config[0], client_id: config[1].to_u64) | |
puts client | |
client.on_message_create do |payload| | |
command = payload.content | |
line = command.split("\n") | |
x = line.size | |
if payload.author.bot | |
else | |
if payload.channel_id == config[2].to_u64 | |
# puts payload.channel_id | |
until x = -1 | |
line[x] = line[x].gsub(/[[:punct:]]/, "") | |
puts line[x].syllable_count | |
x -= 1 | |
end | |
if line.size != 3 | |
puts "Invalid Haiku! Too little or too many lines!" | |
#client.create_message(payload.channel_id, "Invalid Haiku! Too little or too many lines!") | |
client.delete_message(config[2].to_u64, payload.id) | |
else | |
if command.gsub(/[^[:word:]\s]/, "").syllable_count != 17 | |
puts "Invalid Haiku! Too many syllables!" | |
#client.create_message(payload.channel_id, "Invalid Haiku! Too many syllables!") | |
client.delete_message(config[2].to_u64, payload.id) | |
else | |
puts line[0].syllable_count | |
puts line[1].syllable_count | |
puts line[2].syllable_count | |
if line[0].syllable_count == 5 && line[1].syllable_count == 7 && line[2].syllable_count == 5 | |
puts "Valid Haiku." | |
else | |
#client.create_message(payload.channel_id, "Invalid Haiku! Wrong number of syllables on each line") | |
puts "Invalid Haiku! Wrong number of syllables on each line!" | |
client.delete_message(config[2].to_u64, payload.id) | |
end | |
end | |
end | |
else | |
sleep 0 | |
end | |
end | |
end | |
client.run | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment