Browse Source

first!!1!

haliphax 3 years ago
commit
581b60d14a
8 changed files with 119 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 21 0
      LICENSE
  3. 15 0
      README.md
  4. 22 0
      __init__.py
  5. 15 0
      config.py
  6. 1 0
      local/__init__.py
  7. 37 0
      plugin.py
  8. 7 0
      test.py

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+*.pyc

+ 21 - 0
LICENSE

@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 haliphax
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 15 - 0
README.md

@@ -0,0 +1,15 @@
+# supybot Greet plugin
+
+This plugin will send a privmsg to users when joining a channel where it is
+enabled and a greeting message has been set. It is simple in that it does
+not consider netsplits or known users; it just sends the message for every
+join.
+
+## settings
+
+- `supybot.plugins.Greet.enable` (Boolean): Whether or not the plugin is
+  active on the selected channel
+- `supybot.plugins.Greet.message` (String): The message to send to users when
+  they join the selected channel
+
+To set these, use the `config channel` command.

+ 22 - 0
__init__.py

@@ -0,0 +1,22 @@
+"""
+Add a description of the plugin (to be presented to the user inside the wizard)
+here.  This should describe *what* the plugin does.
+"""
+
+import supybot
+import supybot.world as world
+
+__version__ = ""
+__author__ = supybot.Author('haliphax', 'haliphax', 'haliphax@nope')
+__contributors__ = {}
+__url__ = 'https://github.com/haliphax/supybot-greet'
+
+import config
+import plugin
+reload(plugin)
+
+if world.testing:
+    import test
+
+Class = plugin.Class
+configure = config.configure

+ 15 - 0
config.py

@@ -0,0 +1,15 @@
+import supybot.conf as conf
+import supybot.registry as registry
+
+def configure(advanced):
+    conf.registerPlugin('Greet', True)
+
+
+Greet = conf.registerPlugin('Greet')
+conf.registerChannelValue(Greet, 'enable',
+    registry.Boolean(False, """Determines whether or not the bot will send
+    the configured greeting (defined by supybot.plugins.Greet.message)
+    when someone joins the channel."""))
+conf.registerChannelValue(Greet, 'message',
+    registry.String('', """The greeting that is sent to someone when
+    they join the channel."""))

+ 1 - 0
local/__init__.py

@@ -0,0 +1 @@
+# Stub so local is a module, used for third-party modules

+ 37 - 0
plugin.py

@@ -0,0 +1,37 @@
+import supybot.utils as utils
+from supybot.commands import *
+import supybot.plugins as plugins
+import supybot.ircutils as ircutils
+import supybot.callbacks as callbacks
+import supybot.ircmsgs as ircmsgs
+
+
+class Greet(callbacks.Plugin):
+    """
+    This plugin greets users with a defined message when they join the
+    channel. In order to use this plugin, supybot.plugins.Greet.enable
+    must be True, and supybot.plugins.Greet.message must be set to the
+    message you wish to send to users when they join.
+    """
+
+    def __init__(self, irc):
+        self.__parent = super(Greet, self)
+        self.__parent.__init__(irc)
+
+    def doJoin(self, irc, msg):
+        channel = msg.args[0]
+
+        if not self.registryValue('enable', channel):
+            return
+
+        greeting = self.registryValue('message', channel)
+
+        if len(greeting.strip()) == 0:
+            self.log.warn('Greeting empty for %s' % channel)
+            return
+
+        if not ircutils.strEqual(msg.nick, irc.nick):
+            irc = callbacks.SimpleProxy(irc, msg)
+            irc.queueMsg(ircmsgs.privmsg(msg.nick, greeting))
+
+Class = Greet

+ 7 - 0
test.py

@@ -0,0 +1,7 @@
+from supybot.test import *
+
+class GreetTestCase(PluginTestCase):
+    plugins = ('Greet',)
+
+    def testGreet(self):
+        self.assertNotError('greet')