mirror of
				https://gitlab.com/gpvkt/twitchtts.git
				synced 2025-10-31 00:57:35 +01:00 
			
		
		
		
	Added !wiki command
This commit is contained in:
		
							parent
							
								
									b5b41537d5
								
							
						
					
					
						commit
						c5c2c6201b
					
				
					 6 changed files with 79 additions and 10 deletions
				
			
		
							
								
								
									
										13
									
								
								CHANGELOG.md
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								CHANGELOG.md
									
										
									
									
									
								
							|  | @ -2,9 +2,18 @@ | |||
| 
 | ||||
| All notable changes to this project will be documented in this file. If there is a `Changed` section please read carefully, as this often means that you will need to adapt your `config.yml`, otherwise the bot might fail to start. | ||||
| 
 | ||||
| ## [1.4.1] - unreleased | ||||
| ## [1.5.0] - unreleased | ||||
| 
 | ||||
| ### Fixed 1.4.1 | ||||
| ### Added 1.5.0 | ||||
| 
 | ||||
| * `!wiki` command | ||||
| * `!version` command | ||||
| 
 | ||||
| ### Changed 1.5.0 | ||||
| 
 | ||||
| * Added `!sq` as alias for `!smartquote` | ||||
| 
 | ||||
| ### Fixed 1.5.0 | ||||
| 
 | ||||
| * Darkmode: Options background color | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										12
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								README.md
									
										
									
									
									
								
							|  | @ -53,6 +53,7 @@ bot: | |||
|   subonly: False | ||||
|   modonly: False | ||||
|   message_length: 200 | ||||
|   language: de | ||||
| 
 | ||||
| messages: | ||||
|   toff: "TTS is now inactive." | ||||
|  | @ -72,6 +73,8 @@ messages: | |||
|   quotenotfound: "Sorry, no quote found." | ||||
|   quoteaddedprefix: "Quote:" | ||||
|   quoteaddedsuffix: "added." | ||||
|   wiki_too_many: "Sorry, there are too many possible results. Try a more narrow search." | ||||
|   wiki_no_result: "Sorry, there was an error fetching the wikipedia answer." | ||||
| 
 | ||||
| log: | ||||
|   level: "INFO" | ||||
|  | @ -108,6 +111,7 @@ Please note that the `oauth_token` is valid for approximately 60 days. If it bec | |||
| * `subonly`: If `True` only Subs can use TTS | ||||
| * `modonly`: If `True` only Mods can use TTS | ||||
| * `message_length`: Maximum allowed message length for TTS | ||||
| * `language`: Language for `!wiki` command | ||||
| 
 | ||||
| ##### messages | ||||
| 
 | ||||
|  | @ -128,6 +132,8 @@ Please note that the `oauth_token` is valid for approximately 60 days. If it bec | |||
| * `quotenotfound`: Message if requests quote wasn't found. | ||||
| * `quoteaddedprefix`: Prefix for `Quote <number> added` message. | ||||
| * `quoteaddedsuffix`: Suffix for `Quote <number> added` message. | ||||
| * `wiki_too_many`: Message if `!wiki` command has more than one result. | ||||
| * `wiki_no_result`: Message if `!wiki` command hasn't a valid result. | ||||
| 
 | ||||
| ##### log | ||||
| 
 | ||||
|  | @ -198,9 +204,11 @@ The format of `quotes.txt` looks as follows: | |||
| 
 | ||||
| #### !addquote | ||||
| 
 | ||||
| The `!addvote` command adds a new line to `quotes.txt`. It expects two parameters: `!addquote username quote` where `username` is the name of the user to be quoted. | ||||
| The `!addquote` command adds a new line to `quotes.txt`. It expects two parameters: `!addquote username quote` where `username` is the name of the user to be quoted. | ||||
| 
 | ||||
| Only Subs, Mods and Broadcaster are allowed to add quotes. | ||||
| #### !wiki | ||||
| 
 | ||||
| The `!wiki` command searchs the wikipedia and fetches the first three sentences of the result. | ||||
| 
 | ||||
| ## Build | ||||
| 
 | ||||
|  |  | |||
|  | @ -14,6 +14,7 @@ bot: | |||
|   subonly: False # Only Subs can use TTS | ||||
|   modonly: False # Only Mods can use TTS | ||||
|   message_length: 200 # Max. TTS message length | ||||
|   language: de # Language for wikipedia | ||||
| 
 | ||||
| messages: # Things the bot can send as chat message | ||||
|   toff: "TTS is now inactive." | ||||
|  | @ -34,6 +35,8 @@ messages: # Things the bot can send as chat message | |||
|   quotenotfound: "Sorry, no quote found." | ||||
|   quoteaddedprefix: "Quote:" | ||||
|   quoteaddedsuffix: "added." | ||||
|   wiki_too_many: "Sorry, there are too many possible results. Try a more narrow search." | ||||
|   wiki_no_result: "Sorry, there was an error fetching the wikipedia answer." | ||||
| 
 | ||||
| log: | ||||
|   level: "INFO" # Loglevel, valid values are: DEBUG, INFO, WARNING, ERROR, CRITICAL (do not use DEBUG in a production environment) | ||||
|  |  | |||
|  | @ -1,2 +1,5 @@ | |||
| fuzzywuzzy==0.18.0 | ||||
| PyInstaller==5.3 | ||||
| PyYAML==6.0 | ||||
| requests==2.28.1 | ||||
| wikipedia==1.4.0 | ||||
|  |  | |||
							
								
								
									
										
											BIN
										
									
								
								tts.exe
									
										
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								tts.exe
									
										
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										58
									
								
								tts.py
									
										
									
									
									
								
							
							
						
						
									
										58
									
								
								tts.py
									
										
									
									
									
								
							|  | @ -42,6 +42,7 @@ from socketserver import ThreadingMixIn | |||
| 
 | ||||
| import yaml | ||||
| import requests | ||||
| import wikipedia | ||||
| 
 | ||||
| from fuzzywuzzy import process | ||||
| 
 | ||||
|  | @ -170,7 +171,11 @@ class IRC: | |||
|             logging.debug("!addquote command detected") | ||||
|             self.Commands.addquote(self, tags, msg) | ||||
| 
 | ||||
|         if msg.startswith('!smartquote'): | ||||
|         if msg.startswith('!wiki'): | ||||
|             logging.debug("!wiki command detected") | ||||
|             self.Commands.wiki(self, tags, msg) | ||||
| 
 | ||||
|         if msg.startswith('!smartquote') or msg.startswith('!sq'): | ||||
|             logging.debug("!smartquote command detected") | ||||
|             self.Commands.quote(self, tags, msg) | ||||
| 
 | ||||
|  | @ -220,6 +225,10 @@ class IRC: | |||
|                 logging.debug("Ping check received.") | ||||
|                 self.sendmsg(conf['IRC_CHANNEL'], "@"+str(user), "Pong!") | ||||
| 
 | ||||
|             elif msg.startswith('!version'): | ||||
|                 logging.debug("!version command detected") | ||||
|                 self.sendmsg(conf['IRC_CHANNEL'], "/w @"+str(user), VERSION) | ||||
| 
 | ||||
|             elif msg.startswith('!dtts'): | ||||
|                 logging.debug("!dtts command detected") | ||||
|                 self.Commands.dtts(self, msg) | ||||
|  | @ -505,9 +514,40 @@ class IRC: | |||
|                 msg_queue[raw_msg['timestamp']] = [raw_msg['user'], raw_msg['msg']] | ||||
|                 IRC.sendmsg(self, conf['IRC_CHANNEL'], "@"+str(user), msg) | ||||
| 
 | ||||
|         def wiki(self, tags, msg): | ||||
|             """ !wiki command """ | ||||
| 
 | ||||
|             try: | ||||
|                 user = tags['user'] | ||||
|                 wikipedia.set_lang(conf['WIKI_LANG']) | ||||
|                 msg = msg.replace('!wiki', '').strip() | ||||
|                 wikiresult = wikipedia.summary(msg, sentences=3) | ||||
| 
 | ||||
|                 IRC.sendmsg(self, conf['IRC_CHANNEL'], "@"+str(user), wikiresult) | ||||
|                 IRC.sendmsg(self, conf['IRC_CHANNEL'], "@"+str(user), wikipedia.page(msg).url) | ||||
| 
 | ||||
|                 wikiresult = wikiresult.replace('==', '') | ||||
| 
 | ||||
|                 raw_msg = { | ||||
|                     "TTS": True, | ||||
|                     "msg": wikiresult, | ||||
|                     "badges": True, | ||||
|                     "subscriber": True, | ||||
|                     "msgid": True, | ||||
|                     "user": 'wikipedia', | ||||
|                     "length": conf['IRC_TTS_LEN'], | ||||
|                     "queuetime": datetime.datetime.now(), | ||||
|                     "timestamp": str(time.time_ns()) | ||||
|                 } | ||||
|                 msg_queue[raw_msg['timestamp']] = [raw_msg['user'], raw_msg['msg']] | ||||
| 
 | ||||
|             except wikipedia.exceptions.DisambiguationError: | ||||
|                 IRC.sendmsg(self, conf['IRC_CHANNEL'], "@"+str(user), conf['MESSAGE']['WIKI_TOO_MANY']) | ||||
|             except: # pylint: disable=bare-except | ||||
|                 IRC.sendmsg(self, conf['IRC_CHANNEL'], "@"+str(user), conf['MESSAGE']['WIKI_NO_RESULT']) | ||||
| 
 | ||||
|         def quote(self, tags, msg = False): | ||||
|             """ !q command | ||||
|             """ !smartquote command | ||||
| 
 | ||||
|                 Gets a line from quotes.txt. If a number if given as msg | ||||
|                 it fetch the given line number. If a string is given | ||||
|  | @ -515,10 +555,11 @@ class IRC: | |||
|                 it fetch a random line. | ||||
|             """ | ||||
| 
 | ||||
|             user = tags['user'] | ||||
|             query = msg.replace('!smartquote', '').strip() | ||||
| 
 | ||||
|             try: | ||||
|                 user = tags['user'] | ||||
|                 query = msg.replace('!smartquote', '').strip() | ||||
|                 query = msg.replace('!sq', '').strip() | ||||
| 
 | ||||
|                 if query.isdigit(): | ||||
|                     logging.info('Fetching quote #%s', query) | ||||
| 
 | ||||
|  | @ -989,6 +1030,7 @@ def load_config(): | |||
|             conf['IRC_MODONLY'] = cfg.get('bot', {}).get('modonly', False) | ||||
|             conf['IRC_TTS_LEN'] = cfg.get('bot', {}).get('message_length', 200) | ||||
|             conf['TTS_STARTENABLED'] = cfg.get('bot', {}).get('start_enabled', True) | ||||
|             conf['WIKI_LANG'] = cfg.get('bot', {}).get('language', 'en') | ||||
| 
 | ||||
|             conf['LOG_LEVEL'] = cfg.get('log', {}).get('level', "INFO") | ||||
|             conf['HTTP_PORT'] = cfg.get('http', {}).get('port', 80) | ||||
|  | @ -1016,6 +1058,9 @@ def load_config(): | |||
|             conf['MESSAGE']['QUOTE_ADDED_PREFIX'] = cfg.get('messages', {}).get('quoteaddedprefix', "Quote:") | ||||
|             conf['MESSAGE']['QUOTE_ADDED_SUFFIX'] = cfg.get('messages', {}).get('quoteaddedsuffix', "added.") | ||||
| 
 | ||||
|             conf['MESSAGE']['WIKI_TOO_MANY'] = cfg.get('messages', {}).get('wiki_too_many', "Sorry, there are too many possible results. Try a more narrow search.") | ||||
|             conf['MESSAGE']['WIKI_NO_RESULT'] = cfg.get('messages', {}).get('wiki_no_result', "Sorry, there was an error fetching the wikipedia answer.") | ||||
| 
 | ||||
|             conf['USERMAP'] = cfg.get('usermapping', []) | ||||
| 
 | ||||
|             if 'whitelist' in cfg: | ||||
|  | @ -1159,6 +1204,7 @@ if __name__ == "__main__": | |||
|     logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(module)s %(threadName)s %(levelname)s: %(message)s') | ||||
|     sys.tracebacklimit = 3 | ||||
| 
 | ||||
|     VERSION = "1.5.0" | ||||
|     conf = {} | ||||
|     tts_done = [] | ||||
|     msg_queue_raw = [] | ||||
|  | @ -1167,7 +1213,7 @@ if __name__ == "__main__": | |||
|     if sys.argv[1:]: | ||||
|         if sys.argv[1] == "--version": | ||||
|             print('Simple TTS Bot') | ||||
|             print('Version 1.4.0') | ||||
|             print('Version %s', VERSION) | ||||
|             sys.exit(1) | ||||
| 
 | ||||
|     main() | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue