avoid5bot.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. """
  13. from matrix_bot_api.matrix_bot_api import MatrixBotAPI
  14. from matrix_bot_api.mregex_handler import MRegexHandler
  15. from matrix_bot_api.mcommand_handler import MCommandHandler
  16. import time
  17. import sys
  18. USERNAME = "theemacsshibe" # Bot's username
  19. PASSWORD = "get your own lol" # Bot's password
  20. SERVER = "https://disroot.org" # Matrix server URL
  21. def check_e(room, event):
  22. try:
  23. print("got a fifthglyph!")
  24. r = event["content"]["body"].replace("e","_").replace("E","_")
  25. if r.replace("_","") == "":
  26. room.send_text("{}, that wasn't funny.".format(event["sender"]))
  27. else:
  28. room.send_text("{}: Your last post contains fifthglyphs: \"{}\"".format(event["sender"], r))
  29. except Exception as e:
  30. print(e.message)
  31. pass
  32. def main():
  33. print("Connecting...")
  34. bot = MatrixBotAPI(USERNAME, PASSWORD, SERVER)
  35. e_handler = MRegexHandler("(?i)e", check_e)
  36. bot.add_handler(e_handler)
  37. print("Starting polling...")
  38. bot.start_polling()
  39. while True:
  40. time.sleep(1)
  41. if __name__ == "__main__":
  42. main()