Ejemplo n.º 1
0
        public async Task UserImage(string userId, string imageUrl)
        {
            var diUser = _mdr.Members.FirstOrDefault(x => x.Name == userId || x.Id.ToString() == userId);

            if (diUser == null)
            {
                await ReplyAsync("DI user could not be found in the MDR!");
            }
            else
            {
                try
                {
                    new Uri(imageUrl);
                }
                catch (UriFormatException)
                {
                    await ReplyAsync("The image URL is not valid!");

                    return;
                }

                diUser.ImageUrl = imageUrl;

                MasterDivisionRegistry.Save(_mdr);

                await ReplyAsync("Image url for user successfully set!");
            }
        }
Ejemplo n.º 2
0
        public async Task StartAsync()
        {
            try
            {
                ConfigUtil.Load();
            }
            catch (Exception e)
            {
                // Catch the error and show a dialog. The error will be logged when trying to load the config
                // file anyway, so all we need to do here is to ensure that the user knows why the application crashed.
                MessageBox.Show(
                    "An error occurred whilst trying to load the configuration file. Please ensure the configuration file exists and is named correctly.",
                    "Invalid Configuration File",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
            }

            _commands = new CommandService(
                new CommandServiceConfig
            {
                DefaultRunMode = RunMode.Async,
                LogLevel       = LogSeverity.Verbose
            }
                );

            _client = new DiscordSocketClient(
                new DiscordSocketConfig
            {
                LogLevel         = LogSeverity.Verbose,
                MessageCacheSize = 1000
            }
                );

            _mdr = MasterDivisionRegistry.Load() ?? new MasterDivisionRegistry();

            _calendar = new CalendarScheduler(_client, _mdr);

            // Add singletons of all the services we will need.
            var services = new ServiceCollection()
                           .AddSingleton(_client)
                           .AddSingleton(_commands)
                           .AddSingleton(_mdr)
                           .AddSingleton(_calendar)
                           .AddSingleton <CommandHandler>()
                           .AddSingleton <LoggingService>()
                           .AddSingleton <StartupService>();

            // Create the service provider.
            ServiceProvider = new DefaultServiceProviderFactory().CreateServiceProvider(services);

            // Initialize all the services.
            ServiceProvider.GetRequiredService <LoggingService>();
            await ServiceProvider.GetRequiredService <StartupService>().StartAsync();

            ServiceProvider.GetRequiredService <CommandHandler>();

            // Prevent the application from closing.
            await Task.Delay(-1);
        }
Ejemplo n.º 3
0
 private void ProcessTriggers(DIEvent evt, DiscordSocketClient discord, MasterDivisionRegistry mdr, bool isEdit = false)
 {
     foreach (DICalendarTrigger trigger in Triggers)
     {
         if (trigger.EventMatches(evt))
         {
             evt.PostToChannel(trigger.GuildID, trigger.ChannelID, trigger, isEdit);
         }
     }
 }
Ejemplo n.º 4
0
        public async Task UserBind(IUser user, string userId)
        {
            var diUser = _mdr.Members.FirstOrDefault(x => x.Name == userId || x.Id.ToString() == userId);

            if (diUser == null)
            {
                await ReplyAsync("DI user could not be found in the MDR!");
            }
            else
            {
                diUser.DiscordId = user.Id;
                diUser.ImageUrl  = user.GetAvatarUrl();

                MasterDivisionRegistry.Save(_mdr);

                await ReplyAsync("User was successfully bound!");
            }
        }
Ejemplo n.º 5
0
        public void ProcessEvents(Calendar vCal, DiscordSocketClient discord, MasterDivisionRegistry mdr)
        {
            foreach (var calEvt in vCal.Events.OrderBy(x => x.Start.Ticks))
            {
                DIEvent evt = null;

                if (Events.Any(x => x.UID == calEvt.Uid))
                {
                    evt = Events.First(x => x.UID == calEvt.Uid);

                    var description = DIEvent.DetailsRegex.Match(calEvt.Description).Groups[1].Value.Replace("\n\n", "\n").Trim();
                    if (description == string.Empty)
                    {
                        description = calEvt.Description.Replace("\n\n", "\n").Trim();
                    }

                    if (evt.Start != calEvt.DtStart.AsUtc ||
                        evt.End != (calEvt.DtEnd?.AsUtc ?? DateTime.MinValue.ToUniversalTime()) ||
                        evt.RawTitle != calEvt.Summary ||
                        evt.Description != description)
                    {
                        evt.CopyFrom(calEvt);

                        ProcessTriggers(evt, discord, mdr, true);
                    }

                    continue;
                }

                evt = new DIEvent();

                evt.CopyFrom(calEvt);

                Events.Add(evt);

                if (evt.End > DateTime.UtcNow)
                {
                    ProcessTriggers(evt, discord, mdr);
                }
            }
        }
Ejemplo n.º 6
0
 public ModuleMDR(CalendarScheduler calendar, MasterDivisionRegistry mdr)
 {
     _mdr = mdr;
 }
Ejemplo n.º 7
0
 public ModuleAdmin(CalendarScheduler calendar, MasterDivisionRegistry mdr)
 {
     _calendar = calendar;
     _mdr      = mdr;
 }
Ejemplo n.º 8
0
        public async Task UserSelfbind(string userId)
        {
            var diUser = _mdr.Members.FirstOrDefault(x => x.Name == userId || x.Id.ToString() == userId);

            if (diUser == null)
            {
                await ReplyAsync("DI user could not be found in the MDR! Refreshing...");

                lock (_mdr)
                {
                    _mdr.Update();
                }

                diUser = _mdr.Members.FirstOrDefault(x => x.Name == userId || x.Id.ToString() == userId);
            }

            if (diUser == null)
            {
                await ReplyAsync("User can still not be found... Please try again later!");
            }
            else if (diUser.DiscordId != 0 && diUser.DiscordId != Context.User.Id)
            {
                await ReplyAsync("This user is already bound by someone else!");
            }
            else
            {
                if (diUser.Rank != DIRank.Initiate &&
                    diUser.Rank != DIRank.InitiateStar &&
                    diUser.Rank != DIRank.Member &&
                    diUser.Rank != DIRank.Elite &&
                    diUser.Rank != DIRank.Veteran &&
                    diUser.Rank != DIRank.Mentor &&
                    diUser.Rank != DIRank.Associate)
                {
                    await ReplyAsync("The DI rank of the given user is too high for automatic assignment or you is currently listed as 'Away'!");

                    return;
                }

                if (diUser.Position != DIPosition.None &&
                    diUser.Position != DIPosition.RosterLeader)
                {
                    await ReplyAsync("The DI position of the given user is too high for automatic assignment!");

                    return;
                }

                diUser.DiscordId = Context.User.Id;
                diUser.ImageUrl  = Context.User.GetAvatarUrl();

                var roleMap = ConfigUtil.Config.RoleMap.First(x => x.GuildId == Context.Guild.Id);

                var roles = new List <IRole>();

                var rosterKey = diUser.Team + "," + diUser.Roster;

                if (roleMap.Ranks.ContainsKey(diUser.Rank))
                {
                    roles.Add(Context.Guild.GetRole(roleMap.Ranks[diUser.Rank]));
                }

                if (diUser.Position != DIPosition.None && roleMap.Positions.ContainsKey(diUser.Position))
                {
                    roles.Add(Context.Guild.GetRole(roleMap.Positions[diUser.Position]));
                }

                if (roleMap.RosterRoles.ContainsKey(rosterKey))
                {
                    roles.Add(Context.Guild.GetRole(roleMap.RosterRoles[rosterKey]));
                }

                var guildUser = Context.Guild.Users.First(x => x.Id == Context.User.Id);

                try
                {
                    await guildUser.AddRolesAsync(roles.Distinct());

                    if (guildUser.Roles.Contains(Context.Guild.GetRole(roleMap.DefaultRole)))
                    {
                        await guildUser.RemoveRoleAsync(Context.Guild.GetRole(roleMap.DefaultRole));
                    }
                }
                catch (Exception e)
                {
                    e.ToString();
                }

                await guildUser.ModifyAsync((x) => x.Nickname = diUser.Name);

                MasterDivisionRegistry.Save(_mdr);

                await ReplyAsync("User was successfully bound!");
            }
        }