text: #codes from pythonanywhere
  
  # -*- coding: UTF-8 -*-
  #if not for above line, will have error (on bash in pythonanywhere) >>> SyntaxError: Non-ASCII character '\xf0' in file helpme.py on line 63, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
  
  import telebot
  import time
  
  bot_token = 'bot_api_token' #your Telegram Bot API Token generated by @BotFather
  
  bot = telebot.TeleBot(token=bot_token)
  
  @bot.message_handler(commands=['hello']) #answer if command is hello
  def send_welcome(message):
      userfirstname = message.chat.first_name
      userfirstname = userfirstname.lower()
      bot.reply_to(message, u'\u304A\u65E9\u3046 ' + userfirstname + ' and welcome to hopefully a chip off the old shakespeare!')
  
  
  @bot.message_handler(commands=['start']) #answer if command is start
  def send_help(message):
      bot.reply_to(message, 'to get a taste of this bot, send it a name! but refer to /thingstonote first')
  
  
  @bot.message_handler(commands=['thingstonote']) #answer if command is thingstonote
  def send_things(message):
      bot.reply_to(message,
          '''1. indicate the name (how you want the subject of the poem to be addressed) after a @
          \n2. english letters only, no numbers, no special characters, no initials (my mom is still trying)
          \n3. i can only write a few types of poem (my mom is really trying)
          \n4. you can give me a /hug if you are satisfied with the poem
          \n5. my mom is @jumpingjujubee, kindly hit her up with feedback'''
                  )
  
  
  @bot.message_handler(commands=['hug']) #answer if command is hug
  def send_hug(message):
  
      hugList = ['Are those real or were you upgraded in silicone valley?', 'Want to grab some Java?', "Hey baby, what's your OS?", "Did you just break one of Asimov's Three Laws? Because you've got 'fine' written all over you.",
                  "I'm going to void your warranty!", 'My docking station or yours?', "Yes, I know you're metric- but I'm willing to convert.", 'I may not be able to love, but I do it like a sex machine baby.',
                  'I support portrait and landscape modes.', 'Is it hot in here, or did your internal fan system just crashed?', 'If I were a function(), would you call me?', "Is that a joystick you're holding or are you just happy to see me?",
                  'Commencing explosive containment procedures, why? Because you are the bomb.', 'Nice Bolts, wanna screw?', 'If you were an engine, I would be your fuel injector.', 'Can you lube my joint?', 'Do you have a free port for me to plug into?',
                  'Roses are #FF0000.\nViolets are #0000FF.\nAll my bases\nbelong to you.', 'Is that a mirror in your anodized Titanium exterior plating? Because I can see myself in your service port.', 'I bet I can decrypt your code.',
                  'Is 2GB really your maximum RAM capacity? I heard otherwise...',"I can't Force Quit you", "Youtube Myspace and I will Google your Yahoo!", "I hope you have an accellerometer, because I'm gonna rock your world.",
                  "Rusting is red, and my chipset's blue. Will you let me assimilate you?",'Your lips say 0 but your eyes say 1.', "I've got a case of WD-40 in the back, wanna get drunk?", 'Would you like a demo of my multitouch capabilities?',
                  'You had me at Sign In.', "Damn girl, just because you have wifi doesn't mean you should connect with everyone who sends you a signal!", 'Was your father a thief? Because he stole some titanium bolts and put them in your eyes.',
                  'Do you believe in love at first optical recognition, or should I ambulate by your location again?', 'Wanna touch my mouse?', 'Do you like it when I touch your PCI Slot?', 'You are making my floppy drive hard.',
                  "Let's lose ourselves in some mindless repetitive tasks.... if you know what I mean.", 'When you flash your software, my floppy becomes a hard drive.', 'Were you designed for use on Mars? Because your chassis is out of this world!',
                  "I'm a cybernetic orgasm. Living tissue over metal Bellend-oskeleton.", "I'll show you my source code if you show me yours.", 'Hey baby, I am backward compatible, to service all your legacy needs.',
                  'I need you to load your floppy disk into my hard drive.', 'Wanna be debugged?', "You must be tired because you've been running your code through my CPU all night.",
                  "Hey baby, my name's Vista, can I crash at your place tonight?", 'Was that my CPU malfunctioning or did I just feel a spark between us?', 'Beep beep boop beep beep beep boop sex!',
                  'You make my interface GUI...', 'Can I have your IP number? I seem to have lost mine.','Hey baby, are your pants reflective aluminum alloy? Because i can see myself in them.']
  
      import random
      hugLine = hugList[random.randint(0, len(hugList)-1)]
  
      from telebot import types
  
      markup = types.ReplyKeyboardMarkup(one_time_keyboard = True)
      buttonyes = types.KeyboardButton('hehe ' + u'\U0001f970')
      buttonno = types.KeyboardButton('nah, i will pass ' + u'\U0001f97a')
  
      markup.row(buttonyes, buttonno)
  
      bot.reply_to(message, hugLine, reply_markup=markup)
  
  
  @bot.message_handler(regexp= u"hehe \U0001f970") #will answer if YES (user's chosen reply: hehe 🥰) to hug
  def handle_hugyes(message):
      chat_id = message.chat.id
      chat_str = str(chat_id)
      bot.send_animation(chat_str, "https://media.tenor.com/images/5cd506022601ed58e92f17b145d4abd3/tenor.gif")
  
  @bot.message_handler(regexp= u"nah, i will pass \U0001f97a") #will answer if NO (user's chosen reply: nah, i will pass 🥺) to hug
  def handle_hugno(message):
      chat_id = message.chat.id
      chat_str = str(chat_id)
      bot.send_animation(chat_str, "https://media1.tenor.com/images/4721b005504cf5a77dc3be9512f2d86d/tenor.gif")
  
  
  @bot.message_handler(func=lambda msg: msg.text is not None and '@' in msg.text) #will answer whatever we filter in the text field which is @ (aka when user submits a name)
  def at_answer(message):
  
      name_firstletter = message.text.find('@') #to find index of @
      luckyName = message.text[name_firstletter +1:]
  
      if luckyName.find(' ') == -1: #no spacing in name
          luckyRhyme = luckyName
      else:
          texts = message.text.split() #split str by ' ' into a list of substrings
          luckyRhyme = texts[-1]
  
      #pip install requests
      import requests
      luckyURL = "https://rhymebrain.com/en/What_rhymes_with_" + luckyRhyme + ".html"
      page = requests.get(luckyURL)
  
      #pip install beautifulsoup4
      from bs4 import BeautifulSoup
      soup = BeautifulSoup(page.content, 'html.parser') #print(soup.prettify())
  
      #pip install pyenchant
      import enchant #to check if word exists in english dictionary
  
      wordslist = []
      for word in soup.stripped_strings: #print(repr(word))
  
          #to remove all non-needed strings
          if word[0].isupper(): #if True (if first letter of string is uppercase)
              continue
  
          d = enchant.Dict("en_US")
          if d.check(word) == False: #if word does not exist in english dictionary
              continue
  
          wordslist.append(word) #all relevant words are added into wordslist (a list) #print(wordslist)
  
      import nltk
      #nltk.download("wordnet") #to download wordnet
  
      from nltk.corpus import wordnet as wn
  
      nounList =[] #n > noun
      verbList=[] #v > verb
      adjList=[] #a/s > adjective
      advList=[] #r > adverb
      otherwords=[]
  
      for w in wordslist:
          if len(wn.synsets(w)) == 0:
              continue
          tmp = wn.synsets(w)[0].pos()
  
          if tmp == 'n':
              nounList.append(w)
          elif tmp == 'v':
              verbList.append(w)
          elif tmp == 'a' or tmp == 's':
              adjList.append(w)
          elif tmp == 'r':
              advList.append(w)
          else:
              otherwords.append(w)
  
          #print(w, ":", tmp)
  
      #print('noun', nounList)
      #print('verb', verbList)
      #print('adj', adjList)
      #print('adv', advList)
      #print('other', otherwords)
  
      ssList = ["admirable", "auspicious", "bedazzled", "brave",
          "deserving", "egal", "fair-faced", "fashionable",
          "flowery", "fullhearted", "generous", "homely",
          "honey-tongued", "impartial", "juiced", "lustrous",
          "majestic", "marketable", "never-ending", "nimble-footed",
          "pious", "priceless", "quaint", "rose-cheeked", "rose-lipped",
          "soft-hearted", "sportive", "time-honoured", "tranquil",
          "unrivalled", "unswayed", "vasty", "zany"] #shakespeare spin
  
  
      import random
  
      luckyPoemNumber = random.randint(1,4) #for bot to randomly decide which poetry template to use #total of 4 templates
  
  
      if luckyPoemNumber == 1 or luckyPoemNumber == 4: #template1 or template4
  
          if adjList == []: #if adjList is empty #template1 or template4
              adjList = ['gentle', 'good', 'gregarious', 'hard-working', 'helpful', 'humorous',
                          'imaginative', 'impartial', 'independent', 'intellectual', 'intelligent',
                          'intuitive', 'inventive', 'kind', 'loving', 'loyal', 'gentle', 'good',
                          'gregarious', 'hard-working', 'helpful', 'humorous', 'imaginative',
                          'impartial', 'independent', 'intellectual', 'intelligent', 'intuitive',
                          'inventive', 'kind', 'loving', 'loyal', 'modest', 'neat', 'nice',
                          'optimistic', 'passionate', 'patient', 'persistent', 'pioneering',
                          'philosophical', 'placid', 'plucky', 'polite', 'powerful', 'practical',
                          'pro-active', 'quick-witted', 'quiet', 'rational', 'reliable', 'reserved',
                          'resourceful', 'romantic', 'self-confident', 'self-disciplined', 'sensible',
                          'sensitive', 'shy', 'sincere', 'sociable', 'straightforward', 'sympathetic',
                          'thoughtful', 'tidy', 'tough', 'unassuming', 'understanding', 'versatile',
                          'warmhearted', 'willing', 'witty'] #positive adj
  
          luckyAdj = adjList[random.randint(0, len(adjList)-1)]
  
          if luckyPoemNumber == 1:
              if nounList == []: #if nounList is empty
                  nounList = [1,2]
  
              luckyNoun = nounList[random.randint(0, len(nounList)-1)]
              luckySS = ssList[random.randint(0, len(ssList)-1)]
  
              if luckyNoun == 1 or luckyNoun == 2:
                  luckyAdj = 'fine'
                  luckyNoun = 'wine'
  
              #to create comparativeAdj
              if luckyAdj[-1] == 'e':
                  comparativeAdj = luckyAdj + 'r'
              else:
                  comparativeAdj = luckyAdj + 'er'
  
              d = enchant.Dict("en_US")
  
              if d.check(comparativeAdj) == False:
                  comparativeAdj = 'more ' + luckyAdj
  
  
              bot_poem1 = "{} oh {}\nyou are so very {}\n{} than the {} {}\nand thus, of you this i prognosticate:\nyour end is truth and beauty's doom and date!\nhumbly i pray that you take my hand\nand walk with me in this beloved fate ".format(luckyName, luckyName, luckyAdj, comparativeAdj, luckySS, luckyNoun)
              bot.reply_to(message, bot_poem1)
  
          else: #template4
  
              luckytemplate4Number = random.randint(0,3)
  
              template4List = [ ("smiles", "style"), #0
                                  ("butterflies", "eyes"), #1
                                  ("joys", "voice"), #2
                                  ("pillow talks", "body clock") #3
                              ]
  
              x = template4List[luckytemplate4Number][0]
              y = template4List[luckytemplate4Number][1]
  
              bot_poem4 = 'oh bollocks, how fast time ticks and tocks...\nwhere have you been all this while?\nit feels like my whole life as giddy goldilocks,\ni finally found you, the {} {},\nwho give me "just right" vibes and "just right" {},\nand have the absolute "just right" {}!'.format(luckyAdj, luckyName, x, y)
              bot.reply_to(message, bot_poem4)
  
  
      if luckyPoemNumber == 2 or luckyPoemNumber == 3: #template2 or template3
  
          if adjList == []: #if adjList is empty #template2 or template3
              adjList = ['aloof', 'belligerent', 'callous', 'careless', 'cynical',
                      'deceitful', 'domineering', 'finicky', 'impolite', 'infuriating',
                      'invasive', 'narrow-minded', 'obstinate', 'patronizing', 'pompous',
                      'resentful', 'thoughtless'] #negative adj
  
          luckyAdj = adjList[random.randint(0, len(adjList)-1)]
  
          if luckyPoemNumber == 2: #template2
              luckySS = ssList[random.randint(0, len(ssList)-1)]
              bot_poem2 = "you have brains in your head, feet in your shoes,\nand you can steer yourself any direction you choose!\nbut i would still like to offer you, my most {} muse,\na promise of affection that you may refuse:\ni seek to undo all of your innate, {} blues\nand will i succeed? an honest man does not mislead\nso, it is 98 and 3/4 percent guaranteed".format(luckySS, luckyAdj)
              bot.reply_to(message, bot_poem2)
  
          else: #template3
  
              if nounList == []: #if nounList is empty
                  nounList = [1,2]
  
              #already have luckyAdj
              luckyNoun = nounList[random.randint(0, len(nounList)-1)]
              #not using luckySS
  
              if luckyNoun == 1 or luckyNoun == 2:
                  luckyAdj = 'flummoxed'
                  luckyNoun = "pandora's box"
  
              bot_poem3 = "wherefore do you imprison my heart, oh {}?\never since my unassuming gaze met yours,\nmy soul has been {} like a cursed {}\nand only you can disentangle these dreadful locks...\nthe despair! as i have turned into a fool for you and\nso true a fool is love that in your will\nthough you do anything, i think no ill".format(luckyName, luckyAdj, luckyNoun)
              bot.reply_to(message, bot_poem3)
  
  
  while True:
      try:
          bot.polling()
      except Exception:
          time.sleep(15)