journal.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. require './app/commands/base_command.rb'
  2. class JournalCommand < BaseCommand
  3. def self.opts
  4. {
  5. usage: {
  6. character: "Searches for the character by name, can only add entries for your own characters",
  7. title: "A title for the journal, may be blank (defaults to date)",
  8. entry: "The journal entry, should be a paragraph as the character might enter into a diary"
  9. }
  10. }
  11. end
  12. def self.cmd
  13. desc = "Create a short journal entry for a character"
  14. @cmd ||= Command.new(:journal, desc, opts) do |event, name, title, note|
  15. # Find the character
  16. character = Character.restricted_find(name, event.author, ['Archived'])
  17. # Format and create Journal
  18. date = Time.now.strftime("%a, %b %d, %Y")
  19. if !note
  20. note = title
  21. title = date
  22. elsif title == ''
  23. title = date
  24. end
  25. # Create a new Journal Entry with formatted date
  26. journal = JournalEntry.create(
  27. char_id: character.id,
  28. title: title,
  29. date: date,
  30. entry: note
  31. )
  32. # Create response embed and reply
  33. BotResponse.new(
  34. embed: character_embed(
  35. character: character,
  36. event: event,
  37. section: :journal,
  38. journal: journal
  39. )
  40. )
  41. rescue ActiveRecord::RecordNotFound => e
  42. error_embed("Record not Found!", e.message)
  43. end
  44. end
  45. def self.example_command(event)
  46. journal_entry_examples = [
  47. "Today I did a thing, and it was fun. Yay!",
  48. "As I walk through the valley where I harvest my grain, I take a look at my wife and realize she's very plain",
  49. "I want to kill a mother fucker just to see how it feels"
  50. ]
  51. [Character.where(active: 'Active').order('RANDOM()').first.name,
  52. journal_entry_examples.sample]
  53. end
  54. end