示例#1
0
 async def on_raw_reaction_add(self, reactionpayload):
     if not reactionpayload.guild_id:
         return  # Private message
     channelID = utils.load_settings()['chn_rules']
     channel = self.bot.get_channel(int(channelID))
     if channel is None:
         print('Ticket System: Channel not Found!')
     else:
         if reactionpayload.message_id == channel.last_message_id:
             if self.bot.get_user(reactionpayload.user_id):
                 guild = self.bot.get_guild(reactionpayload.guild_id)
                 member = await guild.fetch_member(reactionpayload.user_id)
                 overwrites = {
                     guild.default_role:
                     discord.PermissionOverwrite(read_messages=False),
                     guild.me:
                     discord.PermissionOverwrite(read_messages=True),
                     member:
                     discord.PermissionOverwrite(read_messages=True)
                 }
                 role = discord.utils.get(guild.roles,
                                          name="Member",
                                          id=758349936584032287)
                 await member.add_roles(role)
         else:
             pass
示例#2
0
def load_model():
    model_load_path = constant.load_model_path
    model_save_path = constant.save_path
    state = torch.load(model_load_path,
                       map_location=lambda storage, location: storage)
    arg = state['config']
    load_settings(arg)

    data_loaders_train, data_loaders_val, data_loaders_test, vocab = prepare_data_loaders(
        num_split=1,
        batch_size=constant.batch_size,
        hier=False,
        elmo=constant.elmo,
        dev_with_label=False,
        include_test=True)

    if constant.model == "LSTM":
        model = LstmModel(vocab=vocab,
                          embedding_size=constant.emb_dim,
                          hidden_size=constant.hidden_dim,
                          num_layers=constant.n_layers,
                          is_bidirectional=constant.bidirec,
                          input_dropout=constant.drop,
                          layer_dropout=constant.drop,
                          attentive=constant.attn)
    elif constant.model == "UTRS":
        model = UTransformer(vocab=vocab,
                             embedding_size=constant.emb_dim,
                             hidden_size=constant.hidden_dim,
                             num_layers=constant.hop,
                             num_heads=constant.heads,
                             total_key_depth=constant.depth,
                             total_value_depth=constant.depth,
                             filter_size=constant.filter,
                             act=constant.act)
    elif constant.model == "ELMO":
        model = ELMoEncoder(C=4)
    else:
        print("Model is not defined")
        exit(0)

    model.load_state_dict(state['model'])
    return model, data_loaders_test, vocab, model_save_path
示例#3
0
def player_menu():

    video_dir = os.path.expanduser(
        utils.load_settings()["files"]["video_directory"])
    video_path = select_videofile(video_dir)
    print(video_path)

    menu_items = {
        "Play media locally": play_locally,
        "Send media to Raspberry pi": stream_to_pi.play_pi,
    }
    utils.clear_screen()
    function_to_exec = utils.menu(menu_items)
    function_to_exec(video_path)
示例#4
0
    async def help(self, ctx: SlashContext):
        embed=discord.Embed(title='Commands', color=0x01dae9)
        embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.avatar_url)
        prefix = utils.load_settings()['prefix']
        for path, subdirs, files in os.walk('./src/cogs/commands/'):
            for file in sorted(files):
                if file.endswith('.py'):
                    desc = open(f'{path}/{file}', 'r+').readline()
                    if (desc and desc.split()[0] == '#description'):
                        embed.add_field(name=f'{prefix}{file[:-3]}', value=desc.replace('#description', ''))
                    else: embed.add_field(name=f'{prefix}{file[:-3]}', value='N/A')

        await ctx.respond()
        await ctx.send(embed=embed)
示例#5
0
    async def on_message_delete(self, message):
        try:
            embed = discord.Embed(
                description=
                f'Message sent by {message.author.mention} deleted in {message.channel.mention}',
                color=0xff0000)
            embed.set_author(name=message.author,
                             icon_url=message.author.avatar_url)
            embed.add_field(name="Content", value=message.content)
            embed.set_footer(text=utils.get_time())

            channel = await self.bot.fetch_channel(
                int(utils.load_settings()['chn_log']))
            await channel.send(embed=embed)
        except errors.HTTPException:
            pass
示例#6
0
    async def on_message_edit(self, before, after):
        try:
            embed = discord.Embed(
                description=
                f'Message sent by {before.author.mention} edited in {before.channel.mention}',
                color=0xff5900)
            embed.set_author(name=before.author,
                             icon_url=before.author.avatar_url)
            embed.add_field(name="Before",
                            value=f'{before.content}',
                            inline=False)
            embed.add_field(name="After",
                            value=f'{after.content}',
                            inline=False)
            embed.set_footer(text=utils.get_time())

            channel = await self.bot.fetch_channel(
                int(utils.load_settings()['chn_log']))
            await channel.send(embed=embed)
        except errors.HTTPException:
            pass
示例#7
0
def play_pi(video_path):

    # Loading settings and information
    settings = utils.load_settings()
    rasppi_settings = settings["raspberrypi"]
    port = rasppi_settings["media_serving_port"]
    host_ip = utils.get_ip()
    file_name = video_path.split("/")[-1]

    # Encoding url
    media_link_unencoded = "http://{}:{}/{}".format(host_ip, port, file_name)
    media_link = urllib.parse.quote(media_link_unencoded, safe="/:")

    # Starting http server
    http_thread = threading.Thread(target=http_server, args=(video_path, port))
    http_thread.daemon = True
    http_thread.start()
    ssh_client = connect_ssh(rasppi_settings)

    # Launching on preferred_player
    players = {"vlc": vlc_launch, "omxplayer": omx_launch}

    pref_player = settings["streaming"]["preferred_player"]
    players[pref_player](ssh_client, media_link)
def load_model():
    constant.evaluate = True
    model_load_path = constant.load_model_path
    model_save_path = constant.save_path

    state = torch.load(model_load_path,
                       map_location=lambda storage, location: storage)
    arg = state['config']

    load_settings(arg)

    data_loader_tr, data_loader_val, data_loader_test, vocab = prepare_data_loaders_without_shuffle(
        batch_size=constant.batch_size,
        hier=True,
        elmo=constant.elmo,
        deepmoji=(constant.model == "DEEPMOJI"),
        dev_with_label=False,
        include_test=True)

    if constant.model == "LSTM":
        model = HLstmModel(vocab=vocab,
                           embedding_size=constant.emb_dim,
                           hidden_size=constant.hidden_dim,
                           num_layers=constant.n_layers,
                           is_bidirectional=constant.bidirec,
                           input_dropout=constant.drop,
                           layer_dropout=constant.drop,
                           attentive=constant.attn,
                           multiattentive=constant.multiattn,
                           num_heads=constant.heads,
                           total_key_depth=constant.depth,
                           total_value_depth=constant.depth,
                           super_ratio=constant.super_ratio,
                           double_supervision=constant.double_supervision,
                           context=constant.context)
    elif constant.model == "UTRS":
        model = HUTransformer(
            vocab=vocab,
            embedding_size=constant.emb_dim,
            hidden_size=constant.hidden_dim,
            num_layers=constant.hop,
            num_heads=constant.heads,
            total_key_depth=constant.depth,
            total_value_depth=constant.depth,
            filter_size=constant.filter,
            act=constant.act,
            input_dropout=constant.input_dropout,
            layer_dropout=constant.layer_dropout,
            attention_dropout=constant.attention_dropout,
            relu_dropout=constant.relu_dropout,
        )
    elif constant.model == "ELMO":
        model = HELMoEncoder(H=constant.hidden_dim,
                             L=constant.n_layers,
                             B=constant.bidirec,
                             C=4)
    elif constant.model == "DEEPMOJI":
        model = HDeepMoji(
            vocab=vocab,
            # embedding_size=constant.emb_dim,
            hidden_size=constant.hidden_dim,
            num_layers=constant.n_layers,
            max_length=700,
            input_dropout=0.0,
            layer_dropout=0.0,
            is_bidirectional=False,
            attentive=False,
        )
    else:
        print("Model is not defined")
        exit(0)

    model.load_state_dict(state['model'])
    return model, data_loader_tr, data_loader_val, data_loader_test, vocab, model_save_path
示例#9
0
    def __init__(self, bot):
        self.bot = bot

        self.role_message_id = utils.load_settings()['rules_id']
示例#10
0
from utils.utils import load_settings
from utils.simulation import play_a_game

settings = load_settings("./config/settings.json")['settings']

r = play_a_game(settings, report_frequency='turn')

for t in r:
    print(r[t])
示例#11
0
from enum import auto
import logging
import discord
from discord_slash.context import SlashContext
from utils import utils
from discord import errors
import time
from discord.ext import commands
from discord_slash import SlashCommand, SlashCommandOptionType, SlashContext

bot = commands.Bot(command_prefix=utils.load_settings()['prefix'],
                   intents=discord.Intents.all(),
                   case_insensitive=True)
bot.remove_command('help')

slash = SlashCommand(bot, sync_commands=True)

start_time = time.time()

extensions = [
    # Moderation
    'cogs.commands.moderation.ban',
    'cogs.commands.moderation.kick',
    'cogs.commands.moderation.unban',
    'cogs.commands.moderation.warn',

    # Utils
    'cogs.commands.utils.bdel',
    'cogs.commands.utils.git',
    'cogs.commands.utils.set_chn_log',
    'cogs.commands.utils.set_chn_welcome',