Пример #1
0
        private void UpdateMoonPhase()
        {
            try
            {
                int phase = Helpers.GetMoonPhase(DateTime.UtcNow);
                if (phase == _currentMoonPhase)
                {
                    return;
                }
                _currentMoonPhase = phase;

                Console.WriteLine($"{DateTime.UtcNow} [KumaKaiNi.Discord] Updating moon phase: {_currentMoonPhase}");

                Assembly assembly = Assembly.GetExecutingAssembly();
                using Stream stream      = assembly.GetManifestResourceStream($"KumaKaiNi.Discord.Resources.Phase{phase}.jpg");
                using Image currentPhase = new Image(stream);

                SocketGuild guild = _discord.GetGuild(214268737887404042);
                guild.ModifyAsync(delegate(GuildProperties p) { p.Icon = currentPhase; });
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
            }
        }
Пример #2
0
        private static async Task ChangeServerLocation(SocketMessage msg)
        {
            var    content = msg.Content;
            string newId   = null;

            if (content.Contains("east"))
            {
                newId = "us-east";
            }
            if (content.Contains("west"))
            {
                newId = "us-west";
            }
            if (content.Contains("south"))
            {
                newId = "us-south";
            }
            if (content.Contains("central"))
            {
                newId = "us-central";
            }

            if (newId == null)
            {
                var currentId = Guild.VoiceRegionId;
                var index     = serverLocs.IndexOf(currentId);
                index = (index + 1) % serverLocs.Count;
                newId = serverLocs[index];
            }

            int timeout = 5000;
            var task    = Guild.ModifyAsync(a => a.RegionId = newId);

            if (await Task.WhenAny(task, Task.Delay(timeout)) == task)
            {
                // task completed within timeout
                await msg.Channel.SendMessageAsync($"Voice channel region changed to {newId}!");
            }
            else
            {
                // timeout logic
                Console.WriteLine("Somethings not right pls help");
                await msg.Channel.SendMessageAsync($"We're getting rate limted, try again later...");
            }
        }
Пример #3
0
        // =================================================
        // SERVER RELOCATE COMMAND
        // =================================================

        private async Task RelocateServer(SocketGuild guild, SocketUserMessage msg, string target = "")
        {
            // Names of regions to serach for
            string[] region_list = { "us-south", "us-west", "us-central", "us-east" };

            // If a location was provided, sets the target region
            // If a location was not provided, gets the next region in the list
            if (Array.IndexOf(region_list, target) == -1)
            {
                int current_region_id = Array.IndexOf(region_list, guild.VoiceRegionId);
                target = region_list[(current_region_id + 1) % region_list.Length];
            }

            // Modifies guild settings
            await guild.ModifyAsync(x => { x.RegionId = target; });

            // Posts notification
            await msg.Channel.SendMessageAsync($"Voice Region changed to {target}!");

            PrintLog($"Voice Region changed to {target}");
        }
 public virtual Task ModifyAsync(Action <GuildProperties> func, RequestOptions?options = null)
 {
     return(_socketGuild.ModifyAsync(func, options));
 }
Пример #5
0
        private async Task SetupServerQuick(SocketGuild guild, ISocketMessageChannel channel, SocketMessage message, bool addRulesMessage = true, bool setupWelcomeChannel = true,
                                            bool setupRuleReaction = true)
        {
            //Rules message
            string rules = _quickRulesText;

            if (addRulesMessage)
            {
                //Check rules file, or if rules where provided
                if (message.Attachments.Count != 0)
                {
                    Attachment attachment = message.Attachments.ElementAt(0);
                    if (!attachment.Filename.EndsWith(".txt"))
                    {
                        await channel.SendMessageAsync("The provided rules file isn't in a `.txt` file format!");

                        return;
                    }

                    rules = await Global.HttpClient.GetStringAsync(attachment.Url);
                }

                else if (string.IsNullOrWhiteSpace(rules) && message.Attachments.Count == 0)
                {
                    await channel.SendMessageAsync("You MUST provide a rules file!");

                    return;
                }
            }

            Logger.Log($"Running server quick setup on {guild.Name}({guild.Id})");

            ServerList server = ServerListsManager.GetServer(guild);

            //Setup the roles
            IRole memberRole = RoleUtils.GetGuildRole(guild, "Member");

            //There is already a role called "member"
            if (memberRole != null)
            {
                await memberRole.ModifyAsync(properties => properties.Permissions = _memberRoleGuildPermissions);
            }
            else
            {
                //create a new role called member
                memberRole = await guild.CreateRoleAsync("Member", _memberRoleGuildPermissions);

                await guild.EveryoneRole.ModifyAsync(properties => properties.Permissions = _everyoneRoleGuildPermissions);
            }

            //Setup the welcome channel
            if (setupWelcomeChannel)
            {
                ulong welcomeChannelId;

                //First, lets check if they already have a #welcome channel of sorts
                if (guild.SystemChannel == null)
                {
                    //They don't, so set one up
                    RestTextChannel welcomeChannel =
                        await guild.CreateTextChannelAsync("welcome",
                                                           properties => { properties.Topic    = "Were everyone gets a warm welcome!";
                                                                           properties.Position = 0; });

                    await welcomeChannel.AddPermissionOverwriteAsync(guild.EveryoneRole, _everyoneChannelPermissions);

                    welcomeChannelId = welcomeChannel.Id;
                }
                else
                {
                    //They already do, so alter the pre-existing one to have right perms, and to not have Discord random messages put there
                    await guild.SystemChannel.AddPermissionOverwriteAsync(guild.EveryoneRole, _everyoneChannelPermissions);

                    welcomeChannelId = guild.SystemChannel.Id;

                    await guild.ModifyAsync(properties => properties.SystemChannel = null);
                }

                //Setup welcome message
                server.WelcomeChannelId      = welcomeChannelId;
                server.WelcomeMessageEnabled = true;
                server.GoodbyeMessageEnabled = true;

                //Do a delay
                await Task.Delay(1000);
            }

            //Rule reaction
            if (addRulesMessage && setupRuleReaction)
            {
                //Setup rules channel
                RestTextChannel rulesChannel = await guild.CreateTextChannelAsync("rules",
                                                                                  properties => { properties.Position = 1;
                                                                                                  properties.Topic    = "Rules of this Discord server"; });

                await rulesChannel.AddPermissionOverwriteAsync(guild.EveryoneRole, _everyoneChannelPermissions);

                RestUserMessage rulesMessage = await rulesChannel.SendMessageAsync(rules);

                //Setup rules reaction
                await rulesMessage.AddReactionAsync(new Emoji(RulesEmoji));

                server.RuleReactionEmoji    = RulesEmoji;
                server.RuleMessageId        = rulesMessage.Id;
                server.RuleMessageChannelId = rulesChannel.Id;
                server.RuleRoleId           = memberRole.Id;
                server.RuleEnabled          = true;
            }

            //Setup the rest of the channels

            //General category
            await AddCategoryWithChannels(guild, memberRole, "General", 3);

            //Do a delay between categories
            await Task.Delay(500);

            //Gamming category
            await AddCategoryWithChannels(guild, memberRole, "Gamming", 4);

            //DONE!
            ServerListsManager.SaveServerList();
            await Context.Channel.SendMessageAsync("Quick Setup is done!");

            Logger.Log($"server quick setup on {guild.Name}({guild.Id}) is done!");
        }
Пример #6
0
 public Task ModifyAsync(Action <GuildProperties> func, RequestOptions options = null)
 {
     return(Guild.ModifyAsync(func, options));
 }