├── README.md ├── info.json ├── penis ├── info.json └── penis.py ├── rndstatus ├── info.json └── rndstatus.py ├── insult ├── info.json ├── insult.py └── data │ └── insults.json ├── remindme ├── info.json └── remindme.py ├── trigger ├── info.json └── trigger.py ├── nomassmentions ├── info.json └── nomassmentions.py ├── cleverbot ├── info.json └── cleverbot.py ├── rift ├── info.json └── rift.py ├── stickyroles ├── info.json └── stickyroles.py ├── .gitignore └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # 26-Cogs 2 | This repository, just like Red v2, is no longer being maintained. 3 | 4 | If you're looking for v3 cogs you can find [the repository here](https://github.com/Twentysix26/x26-Cogs). 5 | -------------------------------------------------------------------------------- /info.json: -------------------------------------------------------------------------------- 1 | {"NAME": "26's Cogs", 2 | "AUTHOR" : "Twentysix", 3 | "SHORT": "General purpose cogs", 4 | "DESCRIPTION" : "Thanks for trying out my cogs <3\nIn the unlikely case you haven't joined yet: https://discord.me/Red-DiscordBot" 5 | } -------------------------------------------------------------------------------- /penis/info.json: -------------------------------------------------------------------------------- 1 | { 2 | "AUTHOR" : "Twentysix", 3 | "DESCRIPTION" : "Usage: [p]penis \nThis is 100% accurate.", 4 | "SHORT": "Detects users' penis size with maximum accuracy.", 5 | "NAME" : "Penis", 6 | "TAGS" : ["fun"] 7 | } 8 | -------------------------------------------------------------------------------- /rndstatus/info.json: -------------------------------------------------------------------------------- 1 | { 2 | "AUTHOR" : "Twentysix", 3 | "DESCRIPTION" : "Cycles custom statuses every X seconds.\nLimited to owner.\nSee [prefix]help RandomStatus for details.", 4 | "SHORT" : "Cycles custom game statuses", 5 | "TAGS" : ["game status", "loop"], 6 | "NAME" : "RandomStatus" 7 | } 8 | -------------------------------------------------------------------------------- /insult/info.json: -------------------------------------------------------------------------------- 1 | { 2 | "AUTHOR" : "Airen and JennJenn", 3 | "SHORT" : "Insult people in a creative way", 4 | "DESCRIPTION" : "Insult people in a creative way", 5 | "DISABLED" : false, 6 | "NAME" : "Insult", 7 | "TAGS" : ["insults", "fun"], 8 | "INSTALL_MSG" : "Usage: `[p]insult `" 9 | } 10 | -------------------------------------------------------------------------------- /remindme/info.json: -------------------------------------------------------------------------------- 1 | { 2 | "AUTHOR" : "Twentysix", 3 | "DESCRIPTION" : "Sends you the message you want when the time is up.\nSee [p]help RemindMe\nExample: [p]remindme 3 days Have sushi with Asu and JennJenn", 4 | "SHORT" : "Never forget anything anymore", 5 | "DISABLED" : false, 6 | "NAME" : "RemindMe", 7 | "TAGS" : ["reminder", "memo"] 8 | } 9 | -------------------------------------------------------------------------------- /trigger/info.json: -------------------------------------------------------------------------------- 1 | { 2 | "AUTHOR" : "Twentysix", 3 | "SHORT" : "Create customizable triggers!", 4 | "DESCRIPTION" : "Allows the creation of customizable triggers", 5 | "DISABLED" : false, 6 | "NAME" : "Trigger", 7 | "TAGS" : ["response", "autoresponse"], 8 | "INSTALL_MSG" : "`[p]help trigger` for more info. `[p]help triggerset` for an explanation of the settings.\nTriggers can be annoying. Be responsible and don't abuse them." 9 | } 10 | -------------------------------------------------------------------------------- /nomassmentions/info.json: -------------------------------------------------------------------------------- 1 | { 2 | "AUTHOR" : "Twentysix", 3 | "SHORT" : "Silences outcoming mass mentions", 4 | "DESCRIPTION" : "Makes sure that any mass mention that is about to be sent from Red is silenced", 5 | "DISABLED" : false, 6 | "NAME" : "NoMassMentions", 7 | "TAGS" : ["utility", "mass mentions", "everyone"], 8 | "INSTALL_MSG" : "This cog is commandless. There is nothing to set up. As long as it is loaded it will silence any outcoming mass mention." 9 | } 10 | -------------------------------------------------------------------------------- /cleverbot/info.json: -------------------------------------------------------------------------------- 1 | { 2 | "AUTHOR" : "Twentysix", 3 | "SHORT" : "Talk with Cleverbot!", 4 | "DESCRIPTION" : "Allows for interaction with cleverbot.com through mention/command", 5 | "DISABLED" : false, 6 | "NAME" : "Cleverbot", 7 | "TAGS" : ["chatbot", "cleverbot", "conversation"], 8 | "INSTALL_MSG" : "Needs to be setup with an API key first. See `[p]cleverbot apikey`\n[p]cleverbot ` to talk with cleverbot.\n`@Mention ` works too.\n`[p]cleverbot toggle` disables replies by mention." 9 | } 10 | -------------------------------------------------------------------------------- /nomassmentions/nomassmentions.py: -------------------------------------------------------------------------------- 1 | class NoMassMentions: 2 | """Silences outcoming mass mentions""" 3 | 4 | def __init__(self, bot): 5 | self.bot = bot 6 | self.bot.add_message_modifier(self.cleanse_msg) 7 | 8 | def cleanse_msg(self, m): 9 | return m.replace("@everyone", "@\u200beveryone")\ 10 | .replace("@here", "@\u200bhere") 11 | 12 | def __unload(self): 13 | self.bot.remove_message_modifier(self.cleanse_msg) 14 | 15 | 16 | def setup(bot): 17 | bot.add_cog(NoMassMentions(bot)) 18 | -------------------------------------------------------------------------------- /rift/info.json: -------------------------------------------------------------------------------- 1 | { 2 | "AUTHOR" : "Twentysix", 3 | "SHORT" : "Allows cross server communication through Red", 4 | "DESCRIPTION" : "Communicate with other servers through Red! Works in DMs too.", 5 | "DISABLED" : false, 6 | "NAME" : "Rift", 7 | "TAGS" : ["cross server", "communication", "fun", "trolling", "impersonation"], 8 | "INSTALL_MSG" : "`[p]riftopen` to use it. Remember to type only the channel name. Have fun!\nThis command is usable by everyone. If you want to restrict it to certain users you might want to download the 'permissions' cog." 9 | } 10 | -------------------------------------------------------------------------------- /stickyroles/info.json: -------------------------------------------------------------------------------- 1 | { 2 | "AUTHOR" : "Twentysix", 3 | "SHORT" : "Reapplies specific roles on join", 4 | "DESCRIPTION" : "With this cog you can specify which roles you want to be reapplied on join. This is particularly useful to fight \"role evasion\".", 5 | "NAME" : "StickyRoles", 6 | "TAGS" : ["roles", "utility", "tools", "moderation"], 7 | "INSTALL_MSG" : "The command group is `[p]stickyroles`. Remember that role names are case sensitive. If a user with the roles you specified with `[p]stickyroles add` leaves the server and comes back those roles will be reapplied to them. Make sure that Red has appropriate permissions." 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | 55 | # Sphinx documentation 56 | docs/_build/ 57 | 58 | # PyBuilder 59 | target/ 60 | 61 | #Ipython Notebook 62 | .ipynb_checkpoints 63 | -------------------------------------------------------------------------------- /penis/penis.py: -------------------------------------------------------------------------------- 1 | import discord 2 | import random 3 | from discord.ext import commands 4 | from cogs.utils.chat_formatting import pagify 5 | 6 | 7 | class Penis: 8 | """Penis related commands.""" 9 | 10 | def __init__(self, bot): 11 | self.bot = bot 12 | 13 | @commands.command(pass_context=True) 14 | async def penis(self, ctx, *users: discord.Member): 15 | """Detects user's penis length 16 | 17 | This is 100% accurate. 18 | Enter multiple users for an accurate comparison!""" 19 | if not users: 20 | await self.bot.send_cmd_help(ctx) 21 | return 22 | 23 | dongs = {} 24 | msg = "" 25 | state = random.getstate() 26 | 27 | for user in users: 28 | random.seed(user.id) 29 | dongs[user] = "8{}D".format("=" * random.randint(0, 30)) 30 | 31 | random.setstate(state) 32 | dongs = sorted(dongs.items(), key=lambda x: x[1]) 33 | 34 | for user, dong in dongs: 35 | msg += "**{}'s size:**\n{}\n".format(user.display_name, dong) 36 | 37 | for page in pagify(msg): 38 | await self.bot.say(page) 39 | 40 | 41 | def setup(bot): 42 | bot.add_cog(Penis(bot)) 43 | -------------------------------------------------------------------------------- /insult/insult.py: -------------------------------------------------------------------------------- 1 | import discord 2 | from discord.ext import commands 3 | from .utils.dataIO import fileIO 4 | from random import choice as randchoice 5 | import os 6 | 7 | 8 | class Insult: 9 | 10 | """Airenkun's Insult Cog""" 11 | def __init__(self, bot): 12 | self.bot = bot 13 | self.insults = fileIO("data/insult/insults.json","load") 14 | 15 | @commands.command(pass_context=True, no_pm=True) 16 | async def insult(self, ctx, user : discord.Member=None): 17 | """Insult the user""" 18 | 19 | msg = ' ' 20 | if user != None: 21 | if user.id == self.bot.user.id: 22 | user = ctx.message.author 23 | msg = " How original. No one else had thought of trying to get the bot to insult itself. I applaud your creativity. Yawn. Perhaps this is why you don't have friends. You don't add anything new to any conversation. You are more of a bot than me, predictable answers, and absolutely dull to have an actual conversation with." 24 | await self.bot.say(user.mention + msg) 25 | else: 26 | await self.bot.say(user.mention + msg + randchoice(self.insults)) 27 | else: 28 | await self.bot.say(ctx.message.author.mention + msg + randchoice(self.insults)) 29 | 30 | 31 | def setup(bot): 32 | bot.add_cog(Insult(bot)) 33 | -------------------------------------------------------------------------------- /rift/rift.py: -------------------------------------------------------------------------------- 1 | import discord 2 | from discord.ext import commands 3 | from collections import namedtuple 4 | from cogs.utils.chat_formatting import escape, pagify 5 | 6 | # Commission made for ScarletRaven, who decided to make it public 7 | # for everyone to enjoy 👍 8 | 9 | OpenRift = namedtuple("Rift", ["source", "destination"]) 10 | 11 | 12 | class Rift: 13 | """Communicate with other servers/channels!""" 14 | 15 | def __init__(self, bot): 16 | self.bot = bot 17 | self.open_rifts = {} 18 | 19 | @commands.command(pass_context=True) 20 | async def riftopen(self, ctx, channel): 21 | """Makes you able to communicate with other channels through Red 22 | 23 | This is cross-server. Type only the channel name or the ID.""" 24 | author = ctx.message.author 25 | author_channel = ctx.message.channel 26 | 27 | def check(m): 28 | try: 29 | return channels[int(m.content)] 30 | except: 31 | return False 32 | 33 | channels = self.bot.get_all_channels() 34 | channels = [c for c in channels 35 | if c.name.lower() == channel.lower() or c.id == channel] 36 | channels = [c for c in channels if c.type == discord.ChannelType.text] 37 | 38 | if not channels: 39 | await self.bot.say("No channels found. Remember to type just " 40 | "the channel name, no `#`.") 41 | return 42 | 43 | if len(channels) > 1: 44 | msg = "Multiple results found.\nChoose a server:\n" 45 | for i, channel in enumerate(channels): 46 | msg += "{} - {} ({})\n".format(i, channel.server, channel.id) 47 | for page in pagify(msg): 48 | await self.bot.say(page) 49 | choice = await self.bot.wait_for_message(author=author, 50 | timeout=30, 51 | check=check, 52 | channel=author_channel) 53 | if choice is None: 54 | await self.bot.say("You haven't chosen anything.") 55 | return 56 | channel = channels[int(choice.content)] 57 | else: 58 | channel = channels[0] 59 | 60 | key = "{}-{}".format(author.id, channel.id) 61 | 62 | if key in self.open_rifts: 63 | await self.bot.say("You already have a rift opened for that " 64 | "channel!") 65 | return 66 | 67 | self.open_rifts[key] = OpenRift(source=author_channel, 68 | destination=channel) 69 | 70 | await self.bot.say("A rift has been opened! Everything you say " 71 | "will be relayed to that channel.\n" 72 | "Responses will be relayed here.\nType " 73 | "`exit` to quit.") 74 | msg = "" 75 | while msg == "" or msg is not None: 76 | msg = await self.bot.wait_for_message(author=author, 77 | channel=author_channel) 78 | if msg is not None and msg.content.lower() != "exit": 79 | try: 80 | await self.bot.send_message(channel, msg.content) 81 | except: 82 | await self.bot.say("Couldn't send your message.") 83 | else: 84 | break 85 | del self.open_rifts[key] 86 | await self.bot.say("Rift closed.") 87 | 88 | async def on_message(self, message): 89 | if message.author == self.bot.user: 90 | return 91 | for k, v in self.open_rifts.items(): 92 | if v.destination == message.channel: 93 | msg = "{}: {}".format(message.author, message.content) 94 | msg = escape(msg, mass_mentions=True) 95 | await self.bot.send_message(v.source, msg) 96 | 97 | 98 | def setup(bot): 99 | bot.add_cog(Rift(bot)) 100 | -------------------------------------------------------------------------------- /remindme/remindme.py: -------------------------------------------------------------------------------- 1 | import discord 2 | from discord.ext import commands 3 | from .utils.dataIO import fileIO 4 | import os 5 | import asyncio 6 | import time 7 | import logging 8 | 9 | class RemindMe: 10 | """Never forget anything anymore.""" 11 | 12 | def __init__(self, bot): 13 | self.bot = bot 14 | self.reminders = fileIO("data/remindme/reminders.json", "load") 15 | self.units = {"minute" : 60, "hour" : 3600, "day" : 86400, "week": 604800, "month": 2592000} 16 | 17 | @commands.command(pass_context=True) 18 | async def remindme(self, ctx, quantity : int, time_unit : str, *, text : str): 19 | """Sends you when the time is up 20 | 21 | Accepts: minutes, hours, days, weeks, month 22 | Example: 23 | [p]remindme 3 days Have sushi with Asu and JennJenn""" 24 | time_unit = time_unit.lower() 25 | author = ctx.message.author 26 | s = "" 27 | if time_unit.endswith("s"): 28 | time_unit = time_unit[:-1] 29 | s = "s" 30 | if not time_unit in self.units: 31 | await self.bot.say("Invalid time unit. Choose minutes/hours/days/weeks/month") 32 | return 33 | if quantity < 1: 34 | await self.bot.say("Quantity must not be 0 or negative.") 35 | return 36 | if len(text) > 1960: 37 | await self.bot.say("Text is too long.") 38 | return 39 | seconds = self.units[time_unit] * quantity 40 | future = int(time.time()+seconds) 41 | self.reminders.append({"ID" : author.id, "FUTURE" : future, "TEXT" : text}) 42 | logger.info("{} ({}) set a reminder.".format(author.name, author.id)) 43 | await self.bot.say("I will remind you that in {} {}.".format(str(quantity), time_unit + s)) 44 | fileIO("data/remindme/reminders.json", "save", self.reminders) 45 | 46 | @commands.command(pass_context=True) 47 | async def forgetme(self, ctx): 48 | """Removes all your upcoming notifications""" 49 | author = ctx.message.author 50 | to_remove = [] 51 | for reminder in self.reminders: 52 | if reminder["ID"] == author.id: 53 | to_remove.append(reminder) 54 | 55 | if not to_remove == []: 56 | for reminder in to_remove: 57 | self.reminders.remove(reminder) 58 | fileIO("data/remindme/reminders.json", "save", self.reminders) 59 | await self.bot.say("All your notifications have been removed.") 60 | else: 61 | await self.bot.say("You don't have any upcoming notification.") 62 | 63 | async def check_reminders(self): 64 | while self is self.bot.get_cog("RemindMe"): 65 | to_remove = [] 66 | for reminder in self.reminders: 67 | if reminder["FUTURE"] <= int(time.time()): 68 | try: 69 | await self.bot.send_message(discord.User(id=reminder["ID"]), "You asked me to remind you this:\n{}".format(reminder["TEXT"])) 70 | except (discord.errors.Forbidden, discord.errors.NotFound): 71 | to_remove.append(reminder) 72 | except discord.errors.HTTPException: 73 | pass 74 | else: 75 | to_remove.append(reminder) 76 | for reminder in to_remove: 77 | self.reminders.remove(reminder) 78 | if to_remove: 79 | fileIO("data/remindme/reminders.json", "save", self.reminders) 80 | await asyncio.sleep(5) 81 | 82 | def check_folders(): 83 | if not os.path.exists("data/remindme"): 84 | print("Creating data/remindme folder...") 85 | os.makedirs("data/remindme") 86 | 87 | def check_files(): 88 | f = "data/remindme/reminders.json" 89 | if not fileIO(f, "check"): 90 | print("Creating empty reminders.json...") 91 | fileIO(f, "save", []) 92 | 93 | def setup(bot): 94 | global logger 95 | check_folders() 96 | check_files() 97 | logger = logging.getLogger("remindme") 98 | if logger.level == 0: # Prevents the logger from being loaded again in case of module reload 99 | logger.setLevel(logging.INFO) 100 | handler = logging.FileHandler(filename='data/remindme/reminders.log', encoding='utf-8', mode='a') 101 | handler.setFormatter(logging.Formatter('%(asctime)s %(message)s', datefmt="[%d/%m/%Y %H:%M]")) 102 | logger.addHandler(handler) 103 | n = RemindMe(bot) 104 | loop = asyncio.get_event_loop() 105 | loop.create_task(n.check_reminders()) 106 | bot.add_cog(n) 107 | -------------------------------------------------------------------------------- /rndstatus/rndstatus.py: -------------------------------------------------------------------------------- 1 | import discord 2 | from discord.ext import commands 3 | from .utils.dataIO import fileIO 4 | from .utils import checks 5 | from __main__ import send_cmd_help 6 | from random import choice as rndchoice 7 | import os 8 | import time 9 | 10 | class RandomStatus: 11 | """Cycles random statuses 12 | 13 | If a custom status is already set, it won't change it until 14 | it's back to none. (!set status)""" 15 | 16 | def __init__(self, bot): 17 | self.bot = bot 18 | self.settings = fileIO("data/rndstatus/settings.json", "load") 19 | self.statuses = fileIO("data/rndstatus/statuses.json", "load") 20 | self.last_change = None 21 | 22 | @commands.group(pass_context=True) 23 | @checks.is_owner() 24 | async def rndstatus(self, ctx): 25 | if ctx.invoked_subcommand is None: 26 | await send_cmd_help(ctx) 27 | 28 | @rndstatus.command(name="set", pass_context=True, no_pm=True) 29 | async def _set(self, ctx, *statuses : str): 30 | """Sets Red's random statuses 31 | 32 | Accepts multiple statuses. 33 | Must be enclosed in double quotes in case of multiple words. 34 | Example: 35 | !rndstatus set \"Tomb Raider II\" \"Transistor\" \"with your heart.\" 36 | Shows current list if empty.""" 37 | current_status = ctx.message.server.me.status 38 | if statuses == () or "" in statuses: 39 | await self.bot.whisper("Current statuses: " + " | ".join(self.statuses)) 40 | return 41 | self.statuses = list(statuses) 42 | fileIO("data/rndstatus/statuses.json", "save", self.statuses) 43 | await self.bot.change_presence(status=current_status) 44 | await self.bot.say("Done. Redo this command with no parameters to see the current list of statuses.") 45 | 46 | 47 | @rndstatus.command(pass_context=True) 48 | async def delay(self, ctx, seconds : int): 49 | """Sets interval of random status switch 50 | 51 | Must be 20 or superior.""" 52 | if seconds < 20: 53 | await send_cmd_help(ctx) 54 | return 55 | self.settings["DELAY"] = seconds 56 | fileIO("data/rndstatus/settings.json", "save", self.settings) 57 | await self.bot.say("Interval set to {}".format(str(seconds))) 58 | 59 | async def switch_status(self, message): 60 | if not message.channel.is_private: 61 | current_game = str(message.server.me.game) 62 | current_status = message.server.me.status 63 | 64 | if self.last_change == None: #first run 65 | self.last_change = int(time.perf_counter()) 66 | if len(self.statuses) > 0 and (current_game in self.statuses or current_game == "None"): 67 | new_game = self.random_status(message) 68 | await self.bot.change_presence(game=discord.Game(name=new_game), status=current_status) 69 | 70 | if message.author.id != self.bot.user.id: 71 | if abs(self.last_change - int(time.perf_counter())) >= self.settings["DELAY"]: 72 | self.last_change = int(time.perf_counter()) 73 | new_game = self.random_status(message) 74 | if new_game != None: 75 | if current_game != new_game: 76 | if current_game in self.statuses or current_game == "None": #Prevents rndstatus from overwriting song's titles or 77 | await self.bot.change_presence(game=discord.Game(name=new_game), status=current_status) #custom statuses set with !set status 78 | 79 | def random_status(self, msg): 80 | current = str(msg.server.me.game) 81 | new = str(msg.server.me.game) 82 | if len(self.statuses) > 1: 83 | while current == new: 84 | new = rndchoice(self.statuses) 85 | elif len(self.statuses) == 1: 86 | new = self.statuses[0] 87 | else: 88 | new = None 89 | return new 90 | 91 | def check_folders(): 92 | if not os.path.exists("data/rndstatus"): 93 | print("Creating data/rndstatus folder...") 94 | os.makedirs("data/rndstatus") 95 | 96 | def check_files(): 97 | settings = {"DELAY" : 300} 98 | default = ["her Turn()", "Tomb Raider II", "Transistor", "NEO Scavenger", "Python", "with your heart."] 99 | 100 | f = "data/rndstatus/settings.json" 101 | if not fileIO(f, "check"): 102 | print("Creating empty settings.json...") 103 | fileIO(f, "save", settings) 104 | 105 | f = "data/rndstatus/statuses.json" 106 | if not fileIO(f, "check"): 107 | print("Creating empty statuses.json...") 108 | fileIO(f, "save", default) 109 | 110 | def setup(bot): 111 | check_folders() 112 | check_files() 113 | n = RandomStatus(bot) 114 | bot.add_listener(n.switch_status, "on_message") 115 | bot.add_cog(n) 116 | -------------------------------------------------------------------------------- /stickyroles/stickyroles.py: -------------------------------------------------------------------------------- 1 | import discord 2 | import os 3 | from discord.ext import commands 4 | from collections import defaultdict 5 | from .utils.dataIO import dataIO 6 | from .utils import checks 7 | 8 | default = { 9 | "sticky_roles": [], 10 | "to_reapply" : {} 11 | } 12 | 13 | 14 | class StickyRoles: 15 | """Reapplies specific roles on join""" 16 | 17 | def __init__(self, bot): 18 | self.bot = bot 19 | db = dataIO.load_json("data/stickyroles/stickyroles.json") 20 | self.db = defaultdict(lambda: default.copy(), db) 21 | 22 | @commands.group(pass_context=True, aliases=["stickyrole"]) 23 | @checks.admin() 24 | async def stickyroles(self, ctx): 25 | """Adds / removes roles to be reapplied on join""" 26 | if ctx.invoked_subcommand is None: 27 | await self.bot.send_cmd_help(ctx) 28 | 29 | @stickyroles.command(pass_context=True) 30 | async def add(self, ctx, *, role: discord.Role): 31 | """Adds role to be reapplied on join""" 32 | server = ctx.message.server 33 | if not server.me.top_role.position > role.position: 34 | await self.bot.say("I don't have enough permissions to add that " 35 | "role. Remember to take role hierarchy in " 36 | "consideration.") 37 | return 38 | self.db[server.id]["sticky_roles"].append(role.id) 39 | self.save() 40 | await self.bot.say("That role will now be reapplied on join.") 41 | 42 | @stickyroles.command(pass_context=True) 43 | async def remove(self, ctx, *, role: discord.Role): 44 | """Removes role to be reapplied on join""" 45 | server = ctx.message.server 46 | try: 47 | self.db[server.id]["sticky_roles"].remove(role.id) 48 | except ValueError: 49 | await self.bot.say("That role was never added in the first place.") 50 | else: 51 | self.save() 52 | await self.bot.say("That role won't be reapplied on join.") 53 | 54 | @stickyroles.command(pass_context=True) 55 | async def clear(self, ctx): 56 | """Removes all sticky roles""" 57 | server = ctx.message.server 58 | try: 59 | del self.db[server.id] 60 | except KeyError: 61 | pass 62 | self.save() 63 | await self.bot.say("All sticky roles have been removed.") 64 | 65 | @stickyroles.command(name="list", pass_context=True) 66 | async def _list(self, ctx): 67 | """Lists sticky roles""" 68 | server = ctx.message.server 69 | roles = self.db[server.id].get("sticky_roles", []) 70 | roles = [discord.utils.get(server.roles, id=r) for r in roles] 71 | roles = [r.name for r in roles if r is not None] 72 | if roles: 73 | await self.bot.say("Sticky roles:\n\n" + ", ".join(roles)) 74 | else: 75 | await self.bot.say("No sticky roles. Add some with `{}stickyroles " 76 | "add`".format(ctx.prefix)) 77 | 78 | async def on_member_remove(self, member): 79 | server = member.server 80 | if server.id not in self.db: 81 | return 82 | 83 | save = False 84 | settings = self.db[server.id] 85 | 86 | for role in member.roles: 87 | if role.id in settings["sticky_roles"]: 88 | if member.id not in settings["to_reapply"]: 89 | settings["to_reapply"][member.id] = [] 90 | settings["to_reapply"][member.id].append(role.id) 91 | save = True 92 | 93 | if save: 94 | self.save() 95 | 96 | async def on_member_join(self, member): 97 | server = member.server 98 | if server.id not in self.db: 99 | return 100 | 101 | settings = self.db[server.id] 102 | 103 | if member.id not in settings["to_reapply"]: 104 | return 105 | 106 | to_add = [] 107 | 108 | for role_id in settings["to_reapply"][member.id]: 109 | if role_id not in settings["sticky_roles"]: 110 | continue 111 | role = discord.utils.get(server.roles, id=role_id) 112 | if role: 113 | to_add.append(role) 114 | 115 | del settings["to_reapply"][member.id] 116 | 117 | if to_add: 118 | try: 119 | await self.bot.add_roles(member, *to_add) 120 | except discord.Forbidden: 121 | print("Failed to add roles to {} ({})\n{}\n" 122 | "I lack permissions to do that." 123 | "".format(member, member.id, to_add)) 124 | except discord.HTTPException as e: 125 | print("Failed to add roles to {} ({})\n{}\n" 126 | "{}" 127 | "".format(member, member.id, to_add, e)) 128 | 129 | self.save() 130 | 131 | def save(self): 132 | dataIO.save_json("data/stickyroles/stickyroles.json", self.db) 133 | 134 | 135 | def check_folders(): 136 | if not os.path.exists("data/stickyroles"): 137 | print("Creating data/stickyroles folder...") 138 | os.makedirs("data/stickyroles") 139 | 140 | 141 | def check_files(): 142 | if not dataIO.is_valid_json("data/stickyroles/stickyroles.json"): 143 | print("Creating empty stickyroles.json...") 144 | dataIO.save_json("data/stickyroles/stickyroles.json", {}) 145 | 146 | 147 | def setup(bot): 148 | check_folders() 149 | check_files() 150 | bot.add_cog(StickyRoles(bot)) -------------------------------------------------------------------------------- /cleverbot/cleverbot.py: -------------------------------------------------------------------------------- 1 | from discord.ext import commands 2 | from cogs.utils import checks 3 | from .utils.dataIO import dataIO 4 | import os 5 | import aiohttp 6 | import json 7 | 8 | API_URL = "https://www.cleverbot.com/getreply" 9 | 10 | 11 | class CleverbotError(Exception): 12 | pass 13 | 14 | class NoCredentials(CleverbotError): 15 | pass 16 | 17 | class InvalidCredentials(CleverbotError): 18 | pass 19 | 20 | class APIError(CleverbotError): 21 | pass 22 | 23 | class OutOfRequests(CleverbotError): 24 | pass 25 | 26 | class OutdatedCredentials(CleverbotError): 27 | pass 28 | 29 | 30 | class Cleverbot(): 31 | """Cleverbot""" 32 | 33 | def __init__(self, bot): 34 | self.bot = bot 35 | self.settings = dataIO.load_json("data/cleverbot/settings.json") 36 | self.instances = {} 37 | 38 | @commands.group(no_pm=True, invoke_without_command=True, pass_context=True) 39 | async def cleverbot(self, ctx, *, message): 40 | """Talk with cleverbot""" 41 | author = ctx.message.author 42 | channel = ctx.message.channel 43 | try: 44 | result = await self.get_response(author, message) 45 | except NoCredentials: 46 | await self.bot.send_message(channel, "The owner needs to set the credentials first.\n" 47 | "See: `[p]cleverbot apikey`") 48 | except APIError: 49 | await self.bot.send_message(channel, "Error contacting the API.") 50 | except InvalidCredentials: 51 | await self.bot.send_message(channel, "The token that has been set is not valid.\n" 52 | "See: `[p]cleverbot apikey`") 53 | except OutOfRequests: 54 | await self.bot.send_message(channel, "You have ran out of requests for this month. " 55 | "The free tier has a 5000 requests a month limit.") 56 | except OutdatedCredentials: 57 | await self.bot.send_message(channel, "You need a valid cleverbot.com api key for this to " 58 | "work. The old cleverbot.io service will soon be no " 59 | "longer active. See `[p]help cleverbot apikey`") 60 | else: 61 | await self.bot.say(result) 62 | 63 | @cleverbot.command() 64 | @checks.is_owner() 65 | async def toggle(self): 66 | """Toggles reply on mention""" 67 | self.settings["TOGGLE"] = not self.settings["TOGGLE"] 68 | if self.settings["TOGGLE"]: 69 | await self.bot.say("I will reply on mention.") 70 | else: 71 | await self.bot.say("I won't reply on mention anymore.") 72 | dataIO.save_json("data/cleverbot/settings.json", self.settings) 73 | 74 | @cleverbot.command() 75 | @checks.is_owner() 76 | async def apikey(self, key: str): 77 | """Sets token to be used with cleverbot.com 78 | 79 | You can get it from https://www.cleverbot.com/api/ 80 | Use this command in direct message to keep your 81 | token secret""" 82 | self.settings["cleverbot_key"] = key 83 | self.settings.pop("key", None) 84 | self.settings.pop("user", None) 85 | dataIO.save_json("data/cleverbot/settings.json", self.settings) 86 | await self.bot.say("Credentials set.") 87 | 88 | async def get_response(self, author, text): 89 | payload = {} 90 | payload["key"] = self.get_credentials() 91 | payload["cs"] = self.instances.get(author.id, "") 92 | payload["input"] = text 93 | session = aiohttp.ClientSession() 94 | 95 | async with session.get(API_URL, params=payload) as r: 96 | if r.status == 200: 97 | data = await r.text() 98 | data = json.loads(data, strict=False) 99 | self.instances[author.id] = data["cs"] # Preserves conversation status 100 | elif r.status == 401: 101 | raise InvalidCredentials() 102 | elif r.status == 503: 103 | raise OutOfRequests() 104 | else: 105 | raise APIError() 106 | await session.close() 107 | return data["output"] 108 | 109 | def get_credentials(self): 110 | if "cleverbot_key" not in self.settings: 111 | if "key" in self.settings: 112 | raise OutdatedCredentials() # old cleverbot.io credentials 113 | try: 114 | return self.settings["cleverbot_key"] 115 | except KeyError: 116 | raise NoCredentials() 117 | 118 | async def on_message(self, message): 119 | if not self.settings["TOGGLE"] or message.server is None: 120 | return 121 | 122 | if not self.bot.user_allowed(message): 123 | return 124 | 125 | author = message.author 126 | channel = message.channel 127 | 128 | if message.author.id == self.bot.user.id: 129 | return 130 | 131 | content = message.content 132 | 133 | # I can't just .replace the .mention for a dumb mobile-only bug 134 | # related to nicknames 135 | name_mention = "<@{}>".format(self.bot.user.id) 136 | nick_mention = "<@!{}>".format(self.bot.user.id) 137 | 138 | if content.startswith(name_mention): 139 | text = message.content.replace(name_mention, "", 1).strip() 140 | elif content.startswith(nick_mention): 141 | text = message.content.replace(nick_mention, "", 1).strip() 142 | else: 143 | return 144 | 145 | await self.bot.send_typing(channel) 146 | 147 | try: 148 | response = await self.get_response(author, text) 149 | except NoCredentials: 150 | await self.bot.send_message(channel, "The owner needs to set the credentials first.\n" 151 | "See: `[p]cleverbot apikey`") 152 | except APIError: 153 | await self.bot.send_message(channel, "Error contacting the API.") 154 | except InvalidCredentials: 155 | await self.bot.send_message(channel, "The token that has been set is not valid.\n" 156 | "See: `[p]cleverbot apikey`") 157 | except OutOfRequests: 158 | await self.bot.send_message(channel, "You have ran out of requests for this month. " 159 | "The free tier has a 5000 requests a month limit.") 160 | except OutdatedCredentials: 161 | await self.bot.send_message(channel, "You need a valid cleverbot.com api key for this to " 162 | "work. The old cleverbot.io service will soon be no " 163 | "longer active. See `[p]help cleverbot apikey`") 164 | else: 165 | await self.bot.send_message(channel, response) 166 | 167 | 168 | def check_folders(): 169 | if not os.path.exists("data/cleverbot"): 170 | print("Creating data/cleverbot folder...") 171 | os.makedirs("data/cleverbot") 172 | 173 | 174 | def check_files(): 175 | f = "data/cleverbot/settings.json" 176 | data = {"TOGGLE" : True} 177 | if not dataIO.is_valid_json(f): 178 | dataIO.save_json(f, data) 179 | 180 | 181 | def setup(bot): 182 | check_folders() 183 | check_files() 184 | bot.add_cog(Cleverbot(bot)) 185 | -------------------------------------------------------------------------------- /insult/data/insults.json: -------------------------------------------------------------------------------- 1 | [ 2 | "Yo Mama so fat she sued Xbox 360 for guessing her weight.", 3 | "You're so fat that when you were diagnosed with a flesh eating bacteria - the doctors gave you 87 years to live.", 4 | "You're so fat you've got more chins than a Hong Kong phone book.", 5 | "Yo Mama so fat she's on both sides of the family.", 6 | "Yo Mama so fat that even Dora couldn't explore her.", 7 | "Yo Mama so fat that she doesn't need the internet; she's already world wide.", 8 | "You're so fat that when you farted you started global warming.", 9 | "You're so fat the back of your neck looks like a pack of hot-dogs.", 10 | "You're so fat that when you fell from your bed you fell from both sides.", 11 | "You're so fat when you get on the scale it says \"To be continued.\"", 12 | "You're so fat when you go swimming the whales start singing \"We Are Family\".", 13 | "You're so fat when you stepped on the scale, Buzz Lightyear popped out and said \"To infinity and beyond!\"", 14 | "You're so fat when you turn around, people throw you a welcome back party.", 15 | "You're so fat when you were in school you sat by everybody.", 16 | "You're so fat when you went to the circus the little girl asked if she could ride the elephant.", 17 | "You're so fat when you go on an airplane, you have to pay baggage fees for your ass.", 18 | "You're so fat whenever you go to the beach the tide comes in.", 19 | "You're so fat I could slap your butt and ride the waves.", 20 | "You're so fat I'd have to grease the door frame and hold a Twinkie on the other side just to get you through.", 21 | "Yo Mama so dumb I told her Christmas was around the corner and she went looking for it.", 22 | "You're so dumb it took you 2 hours to watch 60 minutes.", 23 | "Yo Mama so dumb she bought tickets to Xbox Live.", 24 | "You're so dumb that you thought The Exorcist was a workout video.", 25 | "You're so ugly that you went to the salon and it took 3 hours just to get an estimate.", 26 | "You're so ugly that even Scooby Doo couldn't solve that mystery.", 27 | "What is the weighted center between Planet X and Planet Y? Oh it's YOU!", 28 | ":eggplant: :eggplant: :eggplant:", 29 | "Your birth certificate is an apology letter from the condom factory.", 30 | "I wasn't born with enough middle fingers to let you know how I feel about you.", 31 | "You must have been born on a highway because that's where most accidents happen.", 32 | "I'm jealous of all the people that haven't met you.", 33 | "I bet your brain feels as good as new, seeing that you never use it.", 34 | "I'm not saying I hate you, but I would unplug your life support to charge my phone.", 35 | "You're so ugly, when your mom dropped you off at school she got a fine for littering.", 36 | "You bring everyone a lot of joy, when you leave the room.", 37 | "What's the difference between you and eggs? Eggs get laid and you don't.", 38 | "You're as bright as a black hole, and twice as dense.", 39 | "I tried to see things from your perspective, but I couldn't seem to shove my head that far up my ass.", 40 | "Two wrongs don't make a right, take your parents as an example.", 41 | "You're the reason the gene pool needs a lifeguard.", 42 | "If laughter is the best medicine, your face must be curing the world.", 43 | "You're so ugly, when you popped out the doctor said \"Aww what a treasure\" and your mom said \"Yeah, lets bury it.\"", 44 | "I have neither the time nor the crayons to explain this to you.", 45 | "You have two brains cells, one is lost and the other is out looking for it.", 46 | "How many times do I have to flush to get rid of you?", 47 | "I don't exactly hate you, but if you were on fire and I had water, I'd drink it.", 48 | "You shouldn't play hide and seek, no one would look for you.", 49 | "Some drink from the fountain of knowledge; you only gargled.", 50 | "Roses are red violets are blue, God made me pretty, what happened to you?", 51 | "It's better to let someone think you are an Idiot than to open your mouth and prove it.", 52 | "Somewhere out there is a tree, tirelessly producing oxygen so you can breathe. I think you owe it an apology.", 53 | "The last time I saw a face like yours I fed it a banana.", 54 | "The only way you'll ever get laid is if you crawl up a chicken's ass and wait.", 55 | "Which sexual position produces the ugliest children? Ask your mother.", 56 | "If you really want to know about mistakes, you should ask your parents.", 57 | "At least when I do a handstand my stomach doesn't hit me in the face.", 58 | "If I gave you a penny for your thoughts, I'd get change.", 59 | "If I were to slap you, it would be considered animal abuse.", 60 | "Do you know how long it takes for your mother to take a crap? Nine months.", 61 | "What are you going to do for a face when the baboon wants his butt back?", 62 | "Well I could agree with you, but then we'd both be wrong.", 63 | "You're so fat, you could sell shade.", 64 | "It looks like your face caught on fire and someone tried to put it out with a hammer.", 65 | "You're not funny, but your life, now that's a joke.", 66 | "You're so fat the only letters of the alphabet you know are KFC.", 67 | "Oh my God, look at you. Was anyone else hurt in the accident?", 68 | "What are you doing here? Did someone leave your cage open?", 69 | "You're so ugly, the only dates you get are on a calendar.", 70 | "I can explain it to you, but I can't understand it for you.", 71 | "You are proof that God has a sense of humor.", 72 | "If you spoke your mind, you'd be speechless.", 73 | "Why don't you check eBay and see if they have a life for sale.", 74 | "If I wanted to hear from an asshole, I'd fart.", 75 | "You're so fat you need cheat codes to play Wii Fit", 76 | "You're so ugly, when you got robbed, the robbers made you wear their masks.", 77 | "Do you still love nature, despite what it did to you?", 78 | "You are proof that evolution CAN go in reverse.", 79 | "I'll never forget the first time we met, although I'll keep trying.", 80 | "Your parents hated you so much your bath toys were an iron and a toaster", 81 | "Don't feel sad, don't feel blue, Frankenstein was ugly too.", 82 | "You're so ugly, you scared the crap out of the toilet.", 83 | "It's kinda sad watching you attempt to fit your entire vocabulary into a sentence.", 84 | "I fart to make you smell better.", 85 | "You're so ugly you make blind kids cry.", 86 | "You're a person of rare intelligence. It's rare when you show any.", 87 | "You're so fat, when you wear a yellow rain coat people scream ''taxi''.", 88 | "I heard you went to a haunted house and they offered you a job.", 89 | "You look like a before picture.", 90 | "If your brain was made of chocolate, it wouldn't fill an M&M.", 91 | "Aww, it's so cute when you try to talk about things you don't understand.", 92 | "I heard your parents took you to a dog show and you won.", 93 | "You stare at frozen juice cans because they say, \"concentrate\".", 94 | "You're so stupid you tried to wake a sleeping bag.", 95 | "Am I getting smart with you? How would you know?", 96 | "We all sprang from apes, but you didn't spring far enough.", 97 | "I'm no proctologist, but I know an asshole when I see one.", 98 | "When was the last time you could see your whole body in the mirror?", 99 | "You must have a very low opinion of people if you think they are your equals.", 100 | "So, a thought crossed your mind? Must have been a long and lonely journey.", 101 | "You're the best at all you do - and all you do is make people hate you.", 102 | "Looks like you fell off the ugly tree and hit every branch on the way down.", 103 | "Looks aren't everything; in your case, they aren't anything.", 104 | "You have enough fat to make another human.", 105 | "You're so ugly, when you threw a boomerang it didn't come back.", 106 | "You're so fat a picture of you would fall off the wall!", 107 | "Your hockey team made you goalie so you'd have to wear a mask.", 108 | "Ordinarily people live and learn. You just live.", 109 | "Did your parents ever ask you to run away from home?", 110 | "I heard you took an IQ test and they said your results were negative.", 111 | "You're so ugly, you had tinted windows on your incubator.", 112 | "Don't you need a license to be that ugly?", 113 | "I'm not saying you're fat, but it looks like you were poured into your clothes and someone forgot to say \"when\"", 114 | "I've seen people like you, but I had to pay admission!", 115 | "I hear the only place you're ever invited is outside.", 116 | "Keep talking, someday you'll say something intelligent!", 117 | "You couldn't pour water out of a boot if the instructions were on the heel.", 118 | "Even if you were twice as smart, you'd still be stupid!", 119 | "You're so fat, you have to use a mattress as a maxi-pad.", 120 | "I may be fat, but you're ugly, and I can lose weight.", 121 | "I was pro life before I met you.", 122 | "What's the difference between you and Hitler? Hitler knew when to kill himself.", 123 | "You're so fat, your double chin has a double chin.", 124 | "If ignorance is bliss, you must be the happiest person on earth.", 125 | "You're so stupid, it takes you an hour to cook minute rice.", 126 | "Is that your face? Or did your neck just throw up?", 127 | "You're so ugly you have to trick or treat over the phone.", 128 | "I'd hit you but we don't hit girls around here.", 129 | "Dumbass.", 130 | "Bitch.", 131 | "I'd give you a nasty look but you've already got one.", 132 | "If I wanted a bitch, I'd have bought a dog.", 133 | "Scientists say the universe is made up of neutrons, protons and electrons. They forgot to mention morons.", 134 | "Why is it acceptable for you to be an idiot but not for me to point it out?", 135 | "Did you know they used to be called \"Jumpolines\" until your mum jumped on one?", 136 | "You're not stupid; you just have bad luck when thinking.", 137 | "I thought of you today. It reminded me to take the garbage out.", 138 | "I'm sorry I didn't get that - I don't speak idiot.", 139 | "Hey, your village called \u2013 they want their idiot back.", 140 | "I just stepped in something that was smarter than you\u2026 and smelled better too.", 141 | "You're so fat that at the zoo the elephants started throwing you peanuts.", 142 | "You're so fat every time you turn around, it's your birthday.", 143 | "You're so fat your idea of dieting is deleting the cookies from your internet cache.", 144 | "You're so fat your shadow weighs 35 pounds.", 145 | "You're so fat I could tell you to haul ass and you'd have to make two trips.", 146 | "You're so fat I took a picture of you at Christmas and it's still printing.", 147 | "You're so fat I tried to hang a picture of you on my wall, and my wall fell over.", 148 | "You're so fat Mount Everest tried to climb you.", 149 | "You're so fat you can't even jump to a conclusion.", 150 | "You're so fat you can't fit in any timeline.", 151 | "You're so fat you can't fit in this joke.", 152 | "You're so fat you don't skinny dip, you chunky dunk.", 153 | "You're so fat you fell in love and broke it.", 154 | "You're so fat you go to KFC and lick other peoples' fingers.", 155 | "You're so fat you got arrested at the airport for ten pounds of crack.", 156 | "You're so fat you'd have to go to Sea World to get baptized.", 157 | "You're so fat you have your own zip code.", 158 | "You're so fat you have more rolls than a bakery.", 159 | "You're so fat you don't have got cellulite, you've got celluheavy.", 160 | "You're so fat you influence the tides.", 161 | "You're so fat you jumped off the Grand Canyon and got stuck.", 162 | "You're so fat that you laid on the beach and Greenpeace tried to push you back in the water.", 163 | "You're so fat you leave footprints in concrete.", 164 | "You're so fat you need GPS to find your asshole.", 165 | "You're so fat you pull your pants down and your ass is still in them.", 166 | "You're so fat you show up on radar.", 167 | "If you were any less intelligent we'd have to water you three times a week..", 168 | "If your IQ was 3 points higher, you'd be a rock.", 169 | "I would insult you but nature did a better job.", 170 | "Does your ass get jealous of all the shit that comes out of your mouth?", 171 | "If I ate a bowl of alphabet soup, I could shit out a smarter sentence than any of yours.", 172 | "You're not pretty enough to be this stupid.", 173 | "That little voice in the back of your head, telling you you'll never be good enough? It's right.", 174 | "You look like you're going to spend your life having one epiphany after another, always thinking you've finally figured out what's holding you back, and how you can finally be productive and creative and turn your life around. But nothing will ever change. That cycle of mediocrity isn't due to some obstacle. It's who you *are*. The thing standing in the way of your dreams is; that the person having them is *you*.", 175 | "May your day and future be as pleasant as you are.", 176 | "I would agree with you but then we would both be wrong.", 177 | "I bite my thumb at you, sir.", 178 | "I'd call you a tool, but that would imply you were useful in at least one way.", 179 | "I hope you outlive your children.", 180 | "Are you and your dick having a competition to see who can disappoint me the most?", 181 | "Yo mamma is so ugly her portraits hang themselves.", 182 | "Your birth certificate is an apology from the abortion clinic.", 183 | "If you were anymore inbred you'd be a sandwich.", 184 | "Say hello to your wife and my kids for me.", 185 | "You are thick-headed bastards with a bloated bureaucracy, designed to compensate for your small and poor self-esteem, cocksuckers. You have the brains to ban the person who has come to support channel your bot, accusing him of violating the ephemeral ephemeral rules, stupid morons. By the way i have one of the biggest server(5.5k people, ~30 anytime voiceonline members), and i know something about managing, and of these rules - dont be an asshole. You are fucking asshole, maybe it is product of your life alone, or your life with your mom, anyway - you are retard and your soul is a fucking bunch of stupid self-esteems." 186 | ] -------------------------------------------------------------------------------- /trigger/trigger.py: -------------------------------------------------------------------------------- 1 | import discord 2 | import datetime 3 | import os 4 | import asyncio 5 | import re 6 | from discord.ext import commands 7 | from cogs.utils import checks 8 | from cogs.utils.dataIO import dataIO 9 | from cogs.utils.chat_formatting import box, pagify, escape_mass_mentions 10 | from random import choice 11 | 12 | __author__ = "Twentysix" 13 | 14 | 15 | class TriggerError(Exception): 16 | pass 17 | 18 | 19 | class Unauthorized(TriggerError): 20 | pass 21 | 22 | 23 | class NotFound(TriggerError): 24 | pass 25 | 26 | 27 | class AlreadyExists(TriggerError): 28 | pass 29 | 30 | 31 | class Trigger: 32 | """Custom triggers""" 33 | 34 | def __init__(self, bot): 35 | self.bot = bot 36 | self.triggers = [] 37 | self.load_triggers() 38 | self.stats_task = bot.loop.create_task(self.save_stats()) 39 | 40 | @commands.group(pass_context=True, no_pm=True) 41 | async def trigger(self, ctx): 42 | """Trigger creation commands""" 43 | if ctx.invoked_subcommand is None: 44 | await self.bot.send_cmd_help(ctx) 45 | 46 | @trigger.command(pass_context=True) 47 | @checks.admin_or_permissions(administrator=True) 48 | async def create(self, ctx, trigger_name : str, *, triggered_by : str): 49 | """Creates a trigger""" 50 | try: 51 | self.create_trigger(trigger_name, triggered_by, ctx) 52 | except AlreadyExists: 53 | await self.bot.say("A trigger with that name already exists.") 54 | else: 55 | self.save_triggers() 56 | await self.bot.say("Trigger created. Entering interactive " 57 | "add mode...".format(ctx.prefix)) 58 | trigger = self.get_trigger_by_name(trigger_name) 59 | await self.interactive_add_mode(trigger, ctx) 60 | self.save_triggers() 61 | 62 | @trigger.command(pass_context=True) 63 | @checks.admin_or_permissions(administrator=True) 64 | async def delete(self, ctx, trigger_name : str): 65 | """Deletes a trigger""" 66 | try: 67 | self.delete_trigger(trigger_name, ctx) 68 | except Unauthorized: 69 | await self.bot.say("You're not authorized to delete that trigger.") 70 | except NotFound: 71 | await self.bot.say("That trigger doesn't exist.") 72 | else: 73 | await self.bot.say("Trigger deleted.") 74 | 75 | @trigger.command(pass_context=True) 76 | @checks.admin_or_permissions(administrator=True) 77 | async def add(self, ctx, trigger_name : str, *, response : str=None): 78 | """Adds a response to a trigger 79 | 80 | Leaving the response argument empty will enable interactive mode 81 | 82 | Owner only: 83 | Adding a response as 'file: filename.jpg' will send that file as 84 | response if present in data/trigger/files""" 85 | author = ctx.message.author 86 | trigger = self.get_trigger_by_name(trigger_name) 87 | 88 | if trigger is None: 89 | await self.bot.say("That trigger doesn't exist.") 90 | return 91 | if not trigger.can_edit(author): 92 | await self.bot.say("You're not allowed to edit that trigger.") 93 | return 94 | 95 | if response is not None: 96 | trigger.responses.append(response) 97 | await self.bot.say("Response added.") 98 | else: # Interactive mode 99 | await self.interactive_add_mode(trigger, ctx) 100 | self.save_triggers() 101 | 102 | @trigger.command(pass_context=True) 103 | @checks.admin_or_permissions(administrator=True) 104 | async def remove(self, ctx, trigger_name : str): 105 | """Lets you choose a response to remove""" 106 | author = ctx.message.author 107 | trigger = self.get_trigger_by_name(trigger_name) 108 | 109 | if trigger is None: 110 | await self.bot.say("That trigger doesn't exist.") 111 | return 112 | if trigger.responses == []: 113 | await self.bot.say("That trigger has no responses to delete.") 114 | return 115 | if not trigger.can_edit(author): 116 | await self.bot.say("You're not allowed to do that.") 117 | return 118 | 119 | msg = None 120 | current_list = None 121 | past_messages = [] 122 | quit_msg = "\nType 'exit' to quit removal mode." 123 | 124 | while self.get_n_trigger_responses(trigger) is not None: 125 | r_list = self.get_n_trigger_responses(trigger, truncate=100) 126 | if current_list is None: 127 | current_list = await self.bot.say(r_list + quit_msg) 128 | else: 129 | if r_list != current_list.content: 130 | await self.bot.edit_message(current_list, r_list + quit_msg) 131 | msg = await self.bot.wait_for_message(author=author, timeout=15) 132 | if msg is None: 133 | await self.bot.say("Nothing else to remove I guess.") 134 | break 135 | elif msg.content.lower().strip() == "exit": 136 | past_messages.append(msg) 137 | await self.bot.say("Removal mode quit.") 138 | break 139 | try: 140 | i = int(msg.content) 141 | del trigger.responses[i] 142 | except: 143 | pass 144 | past_messages.append(msg) 145 | 146 | if not trigger.responses: 147 | await self.bot.say("No more responses to delete.") 148 | 149 | past_messages.append(current_list) 150 | await self.attempt_cleanup(past_messages) 151 | 152 | async def attempt_cleanup(self, messages): 153 | try: 154 | if len(messages) > 1: 155 | await self.bot.delete_messages(messages) 156 | else: 157 | await self.bot.delete_message(messages[0]) 158 | except: 159 | pass 160 | 161 | @trigger.command(pass_context=True) 162 | async def info(self, ctx, trigger_name : str): 163 | """Shows a trigger's info""" 164 | trigger = self.get_trigger_by_name(trigger_name) 165 | if trigger: 166 | msg = "Name: {}\n".format(trigger.name) 167 | owner_name = discord.utils.get(self.bot.get_all_members(), id=trigger.owner) 168 | owner_name = owner_name if owner_name is not None else "not found" 169 | msg += "Owner: {} ({})\n".format(owner_name, trigger.owner) 170 | trigger_type = "all responses" if trigger.type == "all" else "random response" 171 | msg += "Type: {}\n".format(trigger_type) 172 | influence = "server" if trigger.server is not None else "global" 173 | msg += "Influence: {}\n".format(influence) 174 | cs = "yes" if trigger.case_sensitive else "no" 175 | msg += "Case Sensitive: {}\n".format(cs) 176 | regex = "yes" if trigger.regex else "no" 177 | msg += "Regex: {}\n".format(regex) 178 | msg += "Cooldown: {} seconds\n".format(trigger.cooldown) 179 | msg += "Triggered By: \"{}\"\n".format(trigger.triggered_by.replace("`", "\\`")) 180 | msg += "Payload: {} responses\n".format(len(trigger.responses)) 181 | msg += "Triggered: {} times\n".format(trigger.triggered) 182 | await self.bot.say(box(msg, lang="xl")) 183 | else: 184 | await self.bot.say("There is no trigger with that name.") 185 | 186 | @trigger.command(pass_context=True) 187 | async def show(self, ctx, trigger_name : str): 188 | """Shows all responses of a trigger""" 189 | trigger = self.get_trigger_by_name(trigger_name) 190 | if trigger: 191 | payload = self.elaborate_payload(trigger.responses, truncate=9999) 192 | if payload: 193 | payload = "\n\n".join(payload) 194 | if len(payload) > 2000: 195 | for page in pagify(payload, delims=[" "]): 196 | await self.bot.whisper(page) 197 | else: 198 | await self.bot.say(payload) 199 | else: 200 | await self.bot.say("That trigger has no responses.") 201 | else: 202 | await self.bot.say("That trigger doesn't exist.") 203 | 204 | @trigger.command(name="list", pass_context=True) 205 | async def _list(self, ctx, trigger_type="local"): 206 | """Lists local / global triggers 207 | 208 | Defaults to local""" 209 | server = ctx.message.server 210 | results = [] 211 | if trigger_type == "local": 212 | for trigger in self.triggers: 213 | if trigger.server == server.id: 214 | results.append(trigger) 215 | elif trigger_type == "global": 216 | for trigger in self.triggers: 217 | if trigger.server is None: 218 | results.append(trigger) 219 | else: 220 | await self.bot.say("Invalid type.") 221 | return 222 | if results: 223 | results = ", ".join([r.name for r in results]) 224 | for page in pagify(results, delims=[" ", "\n"]): 225 | await self.bot.say("```\n{}\n```".format(page.lstrip(" "), results)) 226 | else: 227 | await self.bot.say("I couldn't find any trigger of that type.") 228 | 229 | @trigger.command(pass_context=True) 230 | async def search(self, ctx, *, search_terms : str): 231 | """Returns triggers matching the search terms""" 232 | result = self.search_triggers(search_terms.lower()) 233 | if result: 234 | result = ", ".join(sorted([t.name for t in result])) 235 | await self.bot.say("Triggers found:\n\n{}".format(result)) 236 | else: 237 | await self.bot.say("No triggers matching your search.") 238 | 239 | @commands.group(pass_context=True, no_pm=True) 240 | @checks.admin_or_permissions(administrator=True) 241 | async def triggerset(self, ctx): 242 | """Edits the settings of a trigger""" 243 | if ctx.invoked_subcommand is None: 244 | await self.bot.send_cmd_help(ctx) 245 | 246 | @triggerset.command(pass_context=True) 247 | async def cooldown(self, ctx, trigger_name : str, seconds : int): 248 | """Sets the trigger's cooldown""" 249 | author = ctx.message.author 250 | trigger = self.get_trigger_by_name(trigger_name) 251 | if not await self.settings_check(trigger, author): 252 | return 253 | if seconds < 1: 254 | seconds = 1 255 | trigger.cooldown = seconds 256 | self.save_triggers() 257 | await self.bot.say("Cooldown set to {} seconds.".format(seconds)) 258 | 259 | @triggerset.command(pass_context=True) 260 | async def phrase(self, ctx, trigger_name : str, *, triggered_by : str): 261 | """Sets the word/phrase by which the trigger is activated by""" 262 | author = ctx.message.author 263 | trigger = self.get_trigger_by_name(trigger_name) 264 | if not await self.settings_check(trigger, author): 265 | return 266 | if not triggered_by: 267 | await self.bot.say("Invalid setting.") 268 | return 269 | trigger.triggered_by = triggered_by 270 | self.save_triggers() 271 | await self.bot.say("The trigger will be activated by `{}`." 272 | "".format(triggered_by)) 273 | 274 | @triggerset.command(pass_context=True) 275 | async def response(self, ctx, trigger_name : str, _type : str): 276 | """Sets the response type for the trigger. 277 | 278 | Available types: all, random 279 | 280 | All will show all responses in order 281 | Random will pick one at random""" 282 | author = ctx.message.author 283 | trigger = self.get_trigger_by_name(trigger_name) 284 | if not await self.settings_check(trigger, author): 285 | return 286 | _type = _type.lower() 287 | if _type not in ("all", "random"): 288 | await self.bot.say("Invalid type.") 289 | return 290 | trigger.type = _type 291 | self.save_triggers() 292 | await self.bot.say("Response type set to {}.".format(_type)) 293 | 294 | @triggerset.command(pass_context=True) 295 | @checks.is_owner() 296 | async def influence(self, ctx, trigger_name : str, _type : str): 297 | """Sets the influence of the trigger. 298 | 299 | Available types: server, global""" 300 | author = ctx.message.author 301 | server = author.server 302 | trigger = self.get_trigger_by_name(trigger_name) 303 | if not await self.settings_check(trigger, author): 304 | return 305 | _type = _type.lower() 306 | if _type not in ("server", "global"): 307 | await self.bot.say("Invalid type.") 308 | return 309 | trigger.server = server.id if _type == "server" else None 310 | self.save_triggers() 311 | await self.bot.say("Influence set to {}.".format(_type)) 312 | 313 | @triggerset.command(pass_context=True) 314 | async def channels(self, ctx, trigger_name : str, *channels : discord.Channel): 315 | """Sets the channel(s) in which the trigger will be active 316 | 317 | Not entering any channel will revert the trigger to server-wide""" 318 | author = ctx.message.author 319 | server = author.server 320 | trigger = self.get_trigger_by_name(trigger_name) 321 | if not await self.settings_check(trigger, author): 322 | return 323 | if channels: 324 | channels = [c.id for c in channels] 325 | trigger.channels[server.id] = list(channels) 326 | self.save_triggers() 327 | if trigger.server is not None: 328 | await self.bot.say("The trigger will be enabled only on " 329 | "those channels.") 330 | else: 331 | await self.bot.say("In this server the trigger will be " 332 | "enabled only on those channels") 333 | else: 334 | trigger.channels[server.id] = [] 335 | self.save_triggers() 336 | await self.bot.say("The trigger will be active in all channels.") 337 | 338 | @triggerset.command(pass_context=True) 339 | async def casesensitive(self, ctx, trigger_name : str, 340 | true_or_false : bool): 341 | """Toggles the trigger's case sensitivity. 342 | 343 | Can be true or false""" 344 | author = ctx.message.author 345 | trigger = self.get_trigger_by_name(trigger_name) 346 | if not await self.settings_check(trigger, author): 347 | return 348 | trigger.case_sensitive = true_or_false 349 | self.save_triggers() 350 | await self.bot.say("Case sensitivity set to {}.".format(true_or_false)) 351 | 352 | @triggerset.command(pass_context=True) 353 | async def regex(self, ctx, trigger_name : str, true_or_false : bool): 354 | """Toggles the trigger's case capabilities. 355 | 356 | Can be true or false""" 357 | author = ctx.message.author 358 | trigger = self.get_trigger_by_name(trigger_name) 359 | if not await self.settings_check(trigger, author): 360 | return 361 | trigger.regex = true_or_false 362 | self.save_triggers() 363 | await self.bot.say("Regex set to {}.".format(true_or_false)) 364 | 365 | @triggerset.command(pass_context=True) 366 | async def active(self, ctx, trigger_name : str, true_or_false : bool): 367 | """Toggles the trigger on/off. 368 | 369 | Can be true or false""" 370 | author = ctx.message.author 371 | trigger = self.get_trigger_by_name(trigger_name) 372 | if not await self.settings_check(trigger, author): 373 | return 374 | trigger.active = true_or_false 375 | self.save_triggers() 376 | await self.bot.say("Trigger active: {}.".format(true_or_false)) 377 | 378 | async def settings_check(self, trigger, author): 379 | if not trigger: 380 | await self.bot.say("That trigger doesn't exist.") 381 | return False 382 | elif not trigger.can_edit(author): 383 | await self.bot.say("You're not authorized to edit that triggers' " 384 | "settings.") 385 | return False 386 | else: 387 | return True 388 | 389 | def get_trigger_by_name(self, name): 390 | for trigger in self.triggers: 391 | if trigger.name.lower() == name.lower(): 392 | return trigger 393 | return None 394 | 395 | def search_triggers(self, search_terms): 396 | results = [] 397 | for trigger in self.triggers: 398 | if search_terms in trigger.name.lower(): 399 | results.append(trigger) 400 | continue 401 | for payload in trigger.responses: 402 | if search_terms in payload.lower(): 403 | results.append(trigger) 404 | break 405 | else: 406 | if search_terms in trigger.triggered_by.lower(): 407 | results.append(trigger) 408 | return results 409 | 410 | def create_trigger(self, name, triggered_by, ctx): 411 | trigger = self.get_trigger_by_name(name) 412 | if not trigger: 413 | author = ctx.message.author 414 | trigger = TriggerObj(bot=self.bot, 415 | name=name, 416 | triggered_by=triggered_by, 417 | owner=author.id, 418 | server=author.server.id 419 | ) 420 | self.triggers.append(trigger) 421 | else: 422 | raise AlreadyExists() 423 | 424 | def delete_trigger(self, name, ctx): 425 | trigger = self.get_trigger_by_name(name) 426 | if trigger: 427 | if not trigger.can_edit(ctx.message.author): 428 | raise Unauthorized() 429 | self.triggers.remove(trigger) 430 | self.save_triggers() 431 | else: 432 | raise NotFound() 433 | 434 | def elaborate_payload(self, payload, truncate=50, escape=True): 435 | shortened = [] 436 | for p in payload: 437 | if escape: 438 | p = (p.replace("`", "\\`") 439 | .replace("*", "\\*") 440 | .replace("_", "\\_") 441 | .replace("~", "\\~")) 442 | p = escape_mass_mentions(p) 443 | if len(p) < truncate: 444 | shortened.append(p) 445 | else: 446 | shortened.append(p[:truncate] + "...") 447 | return shortened 448 | 449 | async def interactive_add_mode(self, trigger, ctx): 450 | author = ctx.message.author 451 | msg = "" 452 | await self.bot.say("Everything you type will be added as response " 453 | "to the trigger. Type 'exit' to quit.") 454 | while msg is not None: 455 | msg = await self.bot.wait_for_message(author=author, timeout=60) 456 | if msg is None: 457 | await self.bot.say("No more responses then. " 458 | "Your changes have been saved.") 459 | break 460 | if msg.content.lower().strip() == "exit": 461 | await self.bot.say("Your changes have been saved.") 462 | break 463 | trigger.responses.append(msg.content) 464 | 465 | def get_n_trigger_responses(self, trigger, *, truncate=2000): 466 | msg = "" 467 | responses = trigger.responses 468 | i = 0 469 | for r in responses: 470 | if len(r) > truncate: 471 | r = r[:truncate] + "..." 472 | r = r.replace("`", "\\`").replace("*", "\\*").replace("_", "\\_") 473 | msg += "{}. {}\n".format(i, r) 474 | i += 1 475 | if msg != "": 476 | return box(msg, lang="py") 477 | else: 478 | return None 479 | 480 | def is_command(self, msg): 481 | if callable(self.bot.command_prefix): 482 | prefixes = self.bot.command_prefix(self.bot, msg) 483 | else: 484 | prefixes = self.bot.command_prefix 485 | for p in prefixes: 486 | if msg.content.startswith(p): 487 | return True 488 | return False 489 | 490 | def elaborate_response(self, trigger, r): 491 | settings = self.bot.settings 492 | is_owner = (trigger.owner == settings.owner or 493 | trigger.owner in settings.co_owners) 494 | if not is_owner: 495 | return "text", r 496 | if not r.startswith("file:"): 497 | return "text", r 498 | else: 499 | path = r.replace("file:", "").strip() 500 | path = os.path.join("data", "trigger", "files", path) 501 | if os.path.isfile(path): 502 | return "file", path 503 | else: 504 | return "text", r 505 | 506 | async def on_message(self, message): 507 | channel = message.channel 508 | author = message.author 509 | 510 | if message.server is None: 511 | return 512 | 513 | if author == self.bot.user: 514 | return 515 | 516 | if not self.bot.user_allowed(message): 517 | return 518 | 519 | if self.is_command(message): 520 | return 521 | 522 | for trigger in self.triggers: 523 | if not trigger.check(message): 524 | continue 525 | payload = trigger.payload() 526 | for p in payload: 527 | resp_type, resp = self.elaborate_response(trigger, p) 528 | if resp_type == "text": 529 | await self.bot.send_message(channel, resp) 530 | elif resp_type == "file": 531 | await self.bot.send_file(channel, resp) 532 | 533 | async def save_stats(self): 534 | """Saves triggers every 10 minutes to preserve stats""" 535 | await self.bot.wait_until_ready() 536 | try: 537 | await asyncio.sleep(60) 538 | while True: 539 | self.save_triggers() 540 | await asyncio.sleep(60 * 10) 541 | except asyncio.CancelledError: 542 | pass 543 | 544 | def load_triggers(self): 545 | triggers = dataIO.load_json("data/trigger/triggers.json") 546 | for trigger in triggers: 547 | trigger["bot"] = self.bot 548 | self.triggers.append(TriggerObj(**trigger)) 549 | 550 | def save_triggers(self): 551 | triggers = [t.export() for t in self.triggers] 552 | dataIO.save_json("data/trigger/triggers.json", triggers) 553 | 554 | def __unload(self): 555 | self.stats_task.cancel() 556 | self.save_triggers() 557 | 558 | 559 | class TriggerObj: 560 | def __init__(self, **kwargs): 561 | self.bot = kwargs.get("bot") 562 | self.name = kwargs.get("name") 563 | self.owner = kwargs.get("owner") 564 | self.triggered_by = kwargs.get("triggered_by") 565 | self.responses = kwargs.get("responses", []) 566 | self.server = kwargs.get("server") # if it's None, the trigger will be implicitly global 567 | self.channels = kwargs.get("channels", {}) 568 | self.type = kwargs.get("type", "all") # Type of payload. Types: all, random 569 | self.case_sensitive = kwargs.get("case_sensitive", False) 570 | self.regex = kwargs.get("regex", False) 571 | self.cooldown = kwargs.get("cooldown", 1) # Seconds 572 | self.triggered = kwargs.get("triggered", 0) # Counter 573 | self.last_triggered = datetime.datetime(1970, 2, 6) # Initialized 574 | self.active = kwargs.get("active", True) 575 | 576 | def export(self): 577 | data = self.__dict__.copy() 578 | del data["bot"] 579 | del data["last_triggered"] 580 | return data 581 | 582 | def check(self, msg): 583 | if not self.active: 584 | return False 585 | 586 | channels = self.channels.get(msg.server.id, []) 587 | if channels: 588 | if msg.channel.id not in channels: 589 | return False 590 | 591 | content = msg.content 592 | triggered_by = self.triggered_by 593 | 594 | if (self.server == msg.server.id or self.server is None) is False: 595 | return False 596 | 597 | if not self.case_sensitive: 598 | triggered_by = triggered_by.lower() 599 | content = content.lower() 600 | 601 | if not self.regex: 602 | if triggered_by not in content: 603 | return False 604 | else: 605 | found = re.search(triggered_by, content) 606 | if not found: 607 | return False 608 | 609 | timestamp = datetime.datetime.now() 610 | passed = (timestamp - self.last_triggered).seconds 611 | if passed > self.cooldown: 612 | self.last_triggered = timestamp 613 | return True 614 | else: 615 | return False 616 | 617 | def payload(self): 618 | if self.responses: 619 | self.triggered += 1 620 | if self.type == "all": 621 | return self.responses 622 | elif self.type == "random": 623 | if self.responses: 624 | return [choice(self.responses)] 625 | else: 626 | return [] 627 | else: 628 | raise RuntimeError("Invalid trigger type.") 629 | 630 | def can_edit(self, user): 631 | settings = self.bot.settings 632 | server = user.server 633 | admin_role = settings.get_server_admin(server) 634 | # Using the is_owner_check would be better but I don't always have 635 | # context here, nor I feel like mocking it 636 | is_owner = user.id == settings.owner or user.id in settings.co_owners 637 | is_admin = discord.utils.get(user.roles, name=admin_role) is not None 638 | is_trigger_owner = user.id == self.owner 639 | trigger_is_global = self.server is None 640 | if trigger_is_global: 641 | return is_trigger_owner or is_owner 642 | else: 643 | return is_trigger_owner or is_owner or is_admin 644 | 645 | 646 | def check_folders(): 647 | paths = ("data/trigger", "data/trigger/files") 648 | for path in paths: 649 | if not os.path.exists(path): 650 | print("Creating {} folder...".format(path)) 651 | os.makedirs(path) 652 | 653 | 654 | def check_files(): 655 | f = "data/trigger/triggers.json" 656 | if not dataIO.is_valid_json(f): 657 | print("Creating empty triggers.json...") 658 | dataIO.save_json(f, []) 659 | 660 | 661 | def setup(bot): 662 | check_folders() 663 | check_files() 664 | bot.add_cog(Trigger(bot)) 665 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------