Ejemplo n.º 1
0
 private void InitVariables(GuildHandler dataSource)
 {
     _variables = new Dictionary <string, Func <string, string> >
     {
         { "Target", new Func <string, string> (target => target) },
         { "RandomAdmin", new Func <string, string> (target => SelectRandom(dataSource.GetGuild().Users.Where(x => x.GuildPermissions.Administrator)).GetShownName()) },
         { "ServerName", new Func <string, string> (x => dataSource.GetGuild().Name) },
         { "OwnerName", new Func <string, string> (x => dataSource.GetGuild().Owner.GetShownName()) }
     };
 }
Ejemplo n.º 2
0
        public async Task LogAsync(SocketGuild Guild, IUser User, IUser Mod, CaseType CaseType, string Reason)
        {
            var Server = GuildHandler.GetGuild(Guild.Id);

            Reason = Reason ?? $"*Responsible moderator, please type `{Server.Prefix}Reason {Server.Mod.Cases.Count + 1} <Reason>`*";
            var ModChannel = Guild.GetTextChannel(Server.Mod.TextChannel);

            if (ModChannel == null)
            {
                return;
            }
            var Message = await ModChannel.SendMessageAsync($"**{CaseType}** | Case {Server.Mod.Cases.Count + 1}\n**User:** {User} ({User.Id})\n**Reason:** {Reason}\n" +
                                                            $"**Responsible Moderator:** {Mod}");

            Server.Mod.Cases.Add(new CaseWrapper
            {
                User       = $"{User}",
                UserId     = User.Id,
                ModId      = Mod.Id,
                Reason     = Reason,
                CaseType   = CaseType,
                MessageId  = Message.Id,
                CaseNumber = Server.Mod.Cases.Count + 1
            });
            GuildHandler.Save(Server);
        }
Ejemplo n.º 3
0
        public void SaveProfile(ulong GuildId, ulong UserId, UserProfile Profile)
        {
            var Config = GuildHandler.GetGuild(GuildId);

            Config.Profiles[UserId] = Profile;
            GuildHandler.Save(Config);
        }
Ejemplo n.º 4
0
        public void SaveProfile(ulong guildId, ulong userId, UserProfile profile)
        {
            var config = GuildHandler.GetGuild(guildId);

            config.Profiles[userId] = profile;
            GuildHandler.Save(config);
        }
Ejemplo n.º 5
0
 private void PopulateReferenceFunctions()
 {
     _referenceFunctions = new Dictionary <string, Func <SocketGuildUser, string> >
     {
         { "ServerName", (x) => GuildHandler.GetGuild().Name },
         { "ServerIconUrl", (x) => GuildHandler.GetGuild().IconUrl },
         { "ServerOwner", (x) => $"[{GuildHandler.GetGuild ().OwnerId}]" },
         { "DateNow", (x) => DateTime.Now.ToString("dd/MM/yyyy H:mm") },
         { "Joinee", (x) => x.GetShownName() },
     };
 }
Ejemplo n.º 6
0
        public UserProfile GetProfile(ulong guildId, ulong userId)
        {
            var guild = GuildHandler.GetGuild(Client.GetGuild(guildId).Id);

            if (!guild.Profiles.ContainsKey(userId))
            {
                guild.Profiles.Add(userId, new UserProfile());
                GuildHandler.Save(guild);
            }
            return(guild.Profiles[userId]);
        }
        public override void PostInitialize()
        {
            SendMessage("Lomztein-Auto Voice Names", "AddTag", _lockEmoji, "This channel is currently locked.", new Func <SocketVoiceChannel, bool> (x => IsLocked(x.Id)));

            if (!GuildHandler.Plugins.IsPluginActive(_autoVoiceNamePluginName))
            {
                foreach (var channel in GuildHandler.GetGuild().VoiceChannels.Where(x => x.Name.StartsWith(_lockEmoji)))
                {
                    LockChannel(channel.Id, channel.Users.Select(x => x.Id));
                }
            }
        }
Ejemplo n.º 8
0
        private async Task UpdateAll()
        {
            List <SocketGuildUser> users = GuildHandler.GetGuild().Users.ToList();

            foreach (SocketGuildUser u in users)
            {
                if (!_userActivity.GetValue().ContainsKey(u.Id))
                {
                    await RecordActivity(u, GetDefaultDate());
                }
            }
        }
Ejemplo n.º 9
0
        public override void PostInitialize()
        {
            _temporaryChannels = new List <ulong>();
            ResetNameQueue();

            var guild             = GuildHandler.GetGuild();
            var nonCachedChannels = guild.VoiceChannels.Where(x => !_defaultChannels.GetValue().Contains(x.Id));

            _temporaryChannels = nonCachedChannels.Select(x => x.Id).ToList();

            AddGeneralFeaturesStateAttribute("AutomatedVoiceCreation", "Automatic creation of new voice channels when needed.");
        }
Ejemplo n.º 10
0
        public UserProfile GetProfile(ulong GuildId, ulong UserId)
        {
            var Guild = GuildHandler.GetGuild(Client.GetGuild(GuildId).Id);

            if (!Guild.Profiles.ContainsKey(UserId))
            {
                Guild.Profiles.Add(UserId, new UserProfile());
                GuildHandler.Save(Guild);
                return(Guild.Profiles[UserId]);
            }
            return(Guild.Profiles[UserId]);
        }
Ejemplo n.º 11
0
        public override void PostInitialize()
        {
            _nameQueue         = new List <string>();
            _temporaryChannels = new List <ulong>();

            foreach (var value in _newVoiceNames.GetValue())
            {
                _nameQueue.Add(value);
            }

            var guild             = GuildHandler.GetGuild();
            var nonCachedChannels = guild.VoiceChannels.Where(x => !_defaultChannels.GetValue().Contains(x.Id));

            _temporaryChannels = nonCachedChannels.Select(x => x.Id).ToList();
        }
Ejemplo n.º 12
0
 public IContext(IDiscordClient client, IUserMessage message, IServiceProvider serviceProvider)
 {
     Client        = client;
     Message       = message;
     User          = message.Author;
     Channel       = message.Channel;
     Guild         = (message.Channel as IGuildChannel).Guild;
     Random        = serviceProvider.GetRequiredService <Random>();
     HttpClient    = serviceProvider.GetRequiredService <HttpClient>();
     GuildHelper   = serviceProvider.GetRequiredService <GuildHelper>();
     GuildHandler  = serviceProvider.GetRequiredService <GuildHandler>();
     ConfigHandler = serviceProvider.GetRequiredService <ConfigHandler>();
     Config        = ConfigHandler.Config;
     MethodHelper  = serviceProvider.GetRequiredService <MethodHelper>();
     Server        = GuildHandler.GetGuild(Guild.Id);
     Session       = serviceProvider.GetRequiredService <IDocumentStore>().OpenSession();
 }
        private async Task UpdateAll()
        {
            List <SocketGuildUser> users = GuildHandler.GetGuild().Users.ToList();

            foreach (SocketGuildUser u in users)
            {
                if (!_userActivity.GetValue().ContainsKey(u.Id))
                {
                    Core.Log.Plugin($"No last date for user {u.GetShownName ()}. Recording default date.");
                    await RecordActivity(u.Id, GetDefaultDate());
                }
                else
                {
                    await UpdateUser(u.Id);
                }
            }
        }
Ejemplo n.º 14
0
        public Task Start(ulong GuildId)
        {
            var Server = GuildHandler.GetGuild(GuildId);

            if (!Server.Reddit.Subreddits.Any())
            {
                return(Task.CompletedTask);
            }
            if (ChannelTimers.ContainsKey(Server.Reddit.Webhook.TextChannel))
            {
                return(Task.CompletedTask);
            }
            ChannelTimers.TryAdd(Server.Reddit.Webhook.TextChannel, new Timer(async _ =>
            {
                foreach (var Subbredit in Server.Reddit.Subreddits)
                {
                    var PostIds  = new List <string>();
                    var CheckSub = await SubredditAsync(Subbredit).ConfigureAwait(false);
                    if (CheckSub == null)
                    {
                        return;
                    }
                    var SubData = CheckSub.Data.Children[0].ChildData;
                    if (PostTrack.ContainsKey(Server.Reddit.Webhook.TextChannel))
                    {
                        PostTrack.TryGetValue(Server.Reddit.Webhook.TextChannel, out PostIds);
                    }
                    if (PostIds.Contains(SubData.Id))
                    {
                        return;
                    }
                    string Description = SubData.Selftext.Length > 500 ? $"{SubData.Selftext.Substring(0, 400)} ..." : SubData.Selftext;
                    await WebhookService.SendMessageAsync(new WebhookOptions
                    {
                        Message = $"New Post In **r/{SubData.Subreddit}** By **{SubData.Author}**\n**{SubData.Title}**\n{Description}\nPost Link: {SubData.Url}",
                        Name    = "Reddit Feed",
                        Webhook = Server.Reddit.Webhook
                    });
                    PostIds.Add(SubData.Id);
                    PostTrack.TryRemove(Server.Reddit.Webhook.TextChannel, out List <string> Useless);
                    PostTrack.TryAdd(Server.Reddit.Webhook.TextChannel, PostIds);
                }
            }, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(30)));
            return(Task.CompletedTask);
        }
Ejemplo n.º 15
0
        public override void Initialize()
        {
            GuildHandler.ReactionAdded   += OnReactionAdded;
            GuildHandler.ReactionRemoved += OnReactionRemoved;
            SendMessage("Lomztein-Command Root", "AddCommand", karmaCommand);
            karmaCommand.ParentPlugin = this;

            _upvoteEmoteId   = GetConfigCache("UpvoteEmoteId", x => x.GetGuild().Emotes.Where(y => y.Name == "upvote").FirstOrDefault().ZeroIfNull());
            _downvoteEmoteId = GetConfigCache("DownvoteEmoteId", x => x.GetGuild().Emotes.Where(y => y.Name == "downvote").FirstOrDefault().ZeroIfNull());

            _karma = GetDataCache("Karma", x => new Dictionary <ulong, Selfworth>());

            AddConfigInfo("Set Upvote Emote", "Get emote", () => $"Current upvote emote is '{GuildHandler.GetGuild().GetEmoteAsync(_upvoteEmoteId.GetValue()).Result.Name}'.");
            AddConfigInfo("Set Upvote Emote", "Set emote", new Action <string>(x => _upvoteEmoteId.SetValue((GuildHandler.GetGuild().GetEmoteAsync(_upvoteEmoteId.GetValue()).Result?.Id).GetValueOrDefault())),
                          () => $"Set upvote emote to '{GuildHandler.GetGuild().GetEmoteAsync(_upvoteEmoteId.GetValue()).Result?.Name}'.", "Emote");
            AddConfigInfo("Set Downvote Emote", "Get emote", () => $"Current downvote emote is '{GuildHandler.GetGuild().GetEmoteAsync(_downvoteEmoteId.GetValue()).Result.Name}'.");
            AddConfigInfo("Set Downvote Emote", "Set emote", new Action <string>(x => _downvoteEmoteId.SetValue((GuildHandler.GetGuild().GetEmoteAsync(_downvoteEmoteId.GetValue()).Result?.Id).GetValueOrDefault())),
                          () => $"Set downote emote to '{GuildHandler.GetGuild().GetEmoteAsync(_downvoteEmoteId.GetValue()).Result?.Name}'.", "Emote");
        }
Ejemplo n.º 16
0
 private SocketRole[] GetRoles() => GuildHandler.GetGuild().Roles.Where(x => x.Name.StartsWith(_colourRolePrefix.GetValue())).ToArray();
Ejemplo n.º 17
0
 public async Task Intialize()
 {
     await UpdateData(null, _guildHandler.GetGuild());
 }
Ejemplo n.º 18
0
        public override void Initialize()
        {
            GuildHandler.ReactionAdded   += OnReactionAdded;
            GuildHandler.ReactionRemoved += OnReactionRemoved;
            _karmaCommand = new KarmaCommandSet {
                ParentPlugin = this
            };
            SendMessage("Moduthulhu-Command Root", "AddCommand", _karmaCommand);

            _upvoteEmoteId   = GetConfigCache("UpvoteEmoteId", x => x.GetGuild().Emotes.Where(y => y.Name == "upvote").FirstOrDefault().ZeroIfNull());
            _downvoteEmoteId = GetConfigCache("DownvoteEmoteId", x => x.GetGuild().Emotes.Where(y => y.Name == "downvote").FirstOrDefault().ZeroIfNull());

            AddConfigInfo("Set Upvote Emote", "Get emote", () => $"Current upvote emote is '{GuildHandler.GetGuild().GetEmoteAsync(_upvoteEmoteId.GetValue()).Result.Name}'.");
            AddConfigInfo <string>("Set Upvote Emote", "Set emote", x => _upvoteEmoteId.SetValue((GuildHandler.GetGuild().GetEmoteAsync(_upvoteEmoteId.GetValue()).Result?.Id).GetValueOrDefault()),
                                   (success, x) => $"Set upvote emote to '{x}'.", "Emote");
            AddConfigInfo("Set Downvote Emote", "Get emote", () => $"Current downvote emote is '{GuildHandler.GetGuild().GetEmoteAsync(_downvoteEmoteId.GetValue()).Result.Name}'.");
            AddConfigInfo <string>("Set Downvote Emote", "Set emote", x => _downvoteEmoteId.SetValue((GuildHandler.GetGuild().GetEmoteAsync(_downvoteEmoteId.GetValue()).Result?.Id).GetValueOrDefault()),
                                   (success, x) => $"Set downote emote to '{x}'.", "Emote");

            AddGeneralFeaturesStateAttribute("Karma", "Tracking of total upvotes / downvotes per user.");
        }