55# Script metadata
66SCRIPT_NAME = "ollama_bot"
77SCRIPT_AUTHOR = "teraflops"
8- SCRIPT_VERSION = "1.5 "
8+ SCRIPT_VERSION = "1.6 "
99SCRIPT_LICENSE = "MIT"
1010SCRIPT_DESC = "Automatically responds to mentions using Ollama and allows manual queries, including PMs"
1111OLLAMA_API_URL = "http://localhost:11434/api/generate"
1717def setup_config ():
1818 if not weechat .config_is_set_plugin ("highlight_response" ):
1919 weechat .config_set_plugin ("highlight_response" , "on" ) # Enable auto-responses by default
20+ if not weechat .config_is_set_plugin ("pm_response" ):
21+ weechat .config_set_plugin ("pm_response" , "off" ) # Disable PM responses by default
2022setup_config ()
2123
2224def ask_ollama (message ):
@@ -49,7 +51,11 @@ def message_callback(data, buffer, date, tags, displayed, highlight, prefix, mes
4951 username = weechat .info_get ("irc_nick" , "" ) # Get current IRC username
5052 is_mentioned = username .lower () in message .lower ()
5153
52- if int (highlight ) or is_private or is_mentioned :
54+ # Check if PM responses are disabled
55+ if is_private and weechat .config_get_plugin ("pm_response" ) == "off" :
56+ return weechat .WEECHAT_RC_OK
57+
58+ if int (highlight ) or is_mentioned or is_private :
5359 response = ask_ollama (message )
5460 weechat .command (buffer , f"/msg { prefix } { response } " )
5561 return weechat .WEECHAT_RC_OK
@@ -60,8 +66,10 @@ def config_callback(data, option, value):
6066 return weechat .WEECHAT_RC_OK
6167
6268# Register configuration with /set
63- weechat .config_set_desc_plugin ("highlight_response" , "Automatically respond to mentions and PMs (on/off)" )
69+ weechat .config_set_desc_plugin ("highlight_response" , "Automatically respond to mentions in channels (on/off)" )
70+ weechat .config_set_desc_plugin ("pm_response" , "Automatically respond to private messages (on/off)" )
6471weechat .hook_config ("plugins.var.python.ollama_bot.highlight_response" , "config_callback" , "" )
72+ weechat .hook_config ("plugins.var.python.ollama_bot.pm_response" , "config_callback" , "" )
6573
6674# Register commands and hooks
6775weechat .hook_command ("ollama" , "Ask something to Ollama" , "<question>" , "Example: /ollama What is Python?" , "" , "command_ollama" , "" )
0 commit comments