@@ -0,0 +1,2126 @@
+#!/usr/bin/env python3%0Aimport os%0Aimport logging%0Aimport discord%0Afrom discord.ext import commands%0Aimport transliterate%0A%0A%0Alog = logging.getLogger('red.ScriptBan')%0A%0A%0Aclass ScriptBan:%0A    def __init__(self, bot):%0A        self.bot = bot%0A        # scripts: ru,%0A        # modes: whitelist, blacklist%0A        # actions: delete, warn%0A        self.settings = %7B%0A            'scripts': %7B%0A                'ru': %7B%0A                    'mode': 'whitelist',%0A                    'channels': %5B'russian'%5D,%0A                    'action': 'delete',%0A                %7D,%0A            %7D,%0A            'warn': 'Language script %60%25s%60 is not allowed in this channel.',%0A        %7D%0A%0A    async def get_action(self, script, channel):%0A        ''' delete / warn / keep '''%0A        script_sett = self.settings%5B'scripts'%5D%5Bscript%5D%0A%0A        mode = script_sett%5B'mode'%5D%0A        channels = script_sett%5B'channels'%5D%0A        action = script_sett%5B'action'%5D%0A%0A        if mode == 'whitelist':%0A            if channel in channels:%0A                return 'keep'%0A            else:%0A                return action%0A        elif mode == 'blacklist':%0A            if channel in channels:%0A                return 'keep'%0A            else:%0A                return action%0A        else:%0A            raise ValueError%0A%0A    async def handle_message(self, message):%0A        # ignore private messages%0A        if message.channel.is_private:%0A            return%0A%0A        # do not check bot's own messages%0A        if message.author.id == self.bot.user.id:%0A            return%0A%0A        script = transliterate.detect_language(message.clean_content)%0A%0A        if script not in self.settings%5B'scripts'%5D.keys():%0A            return%0A%0A        action = await self.get_action(script, message.channel.name)%0A%0A        if action == 'keep':%0A            return%0A        elif action == 'warn':%0A            await self.bot.reply(self.settings%5B'warn'%5D.format(script))%0A        elif action == 'delete':%0A            await self.bot.delete_message(message)%0A        else:%0A            raise ValueError%0A%0Adef setup(bot):%0A    scriptban = ScriptBan(bot)%0A    bot.add_listener(scriptban.handle_message, 'on_message')%0A    bot.add_cog(scriptban)%0A

add ScriptBan cog