Exemple #1
0
        private async Task Client_Ready(DSharpPlus.EventArgs.ReadyEventArgs e)
        {
            ConsoleLog("client is ready to process events");
            ConsoleLog("Commands:");
            ConsoleLog("1. clear [DM channel ID]");
            ConsoleLog("2. dump [DM channel ID]");
            ConsoleLog("[DM channel ID] argument is optional. Leave it empty to clear/dump all DM messages/channels");
            //ClearMessages().GetAwaiter().GetResult();
            while (true)
            {
                ConsoleLog("Type your command: ", true);
                var readLine   = Console.ReadLine()?.Trim()?.Split(' ');
                var command    = readLine[0];
                var arg        = readLine.Length == 2 ? readLine[1] : null;
                var isValidArg = ulong.TryParse(arg, out ulong id);
                if (arg != null && !isValidArg)
                {
                    ConsoleLog("error: invalid argument type");
                    continue;
                }

                if (command == "clear")
                {
                    await ClearDmChannelAsync(id);
                }
                else if (command == "dump")
                {
                    await GetDump(id);
                }
                else
                {
                    ConsoleLog("error: invalid command");
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Called when Discord is initialized, connected, and ready for commands.
        /// </summary>
        private async Task Discord_Ready(DiscordClient sender, DSharpPlus.EventArgs.ReadyEventArgs e)
        {
            _logger.LogInformation("Discord is ready. Yay!");

            if (Settings.GameStatusMessages.Count > 1)
            {
                if (_statusTimer == null)
                {
                    _statusTimer = new System.Timers.Timer()
                    {
                        Interval  = Settings.ActivityMessageUpdateInterval,
                        AutoReset = true
                    };

                    _statusTimer.Elapsed += StatusTimer_Elapsed;
                }

                _statusTimer.Start();
            }
            else if (Settings.GameStatusMessages.Count == 1)
            {
                _logger.LogInformation("Only one activity message exists; setting it.");
                await Discord.UpdateStatusAsync(_activityList[0]);
            }
            else
            {
                _logger.LogWarning("No activity messages exist; not setting one.");
            }
        }
Exemple #3
0
        /// <summary>
        /// When Bot is up, set up event handlers for guilds and voice channel updates.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        override public async Task ClientReadyAsync(DSharpPlus.EventArgs.ReadyEventArgs e)
        {
            if (!File.Exists("botState.json"))
            {
                State = new BotStateConfig();
            }
            else
            {
                //Deserealize bot last state
                using (var sr = new StreamReader("botState.json")) {
                    State = JsonConvert.DeserializeObject <BotStateConfig>(
                        await sr.ReadToEndAsync()
                        );
                    if (State == null)
                    {
                        State = new BotStateConfig();
                    }
                }
            }

            //Should I discard instead of await this one. If it get's stuck it won't function anywhere past this method
#pragma warning disable CS1998
            e.Client.GuildAvailable += async(e) => _ = InitGuildAsync(e.Guild).ConfigureAwait(false);
#pragma warning restore CS1998

            //This is logically wrong. Seems I've overthought this one
            //foreach (var g in e.Client.Guilds) {
            //	if (g.Value.Name == null)
            //		e.Client.GuildAvailable += async (z) => await InitGuildAsync(z.Guild).ConfigureAwait(false);
            //	else
            //		await InitGuildAsync(g.Value).ConfigureAwait(false);
            //}
        }
Exemple #4
0
        private static async Task Discord_Ready(DiscordClient sender, DSharpPlus.EventArgs.ReadyEventArgs e)
        {
            var discordHelper = Services.GetRequiredService <DiscordHelper>();
            await discordHelper.GetGuild(sender);

            await sender.UpdateStatusAsync(discordHelper.GetActivity($"Nothing, Just chilling 😁"));
        }
Exemple #5
0
 private async Task Discord_Resumed(DiscordClient sender, DSharpPlus.EventArgs.ReadyEventArgs e)
 {
     if (Settings.GameStatusMessages.Count == 1)
     {
         _logger.LogInformation("Only one activity message exists; setting it.");
         await Discord.UpdateStatusAsync(_activityList[0]);
     }
 }
Exemple #6
0
 async Task DiscordApi_Ready(DSharpPlus.EventArgs.ReadyEventArgs e)
 {
     await DiscordApi.UpdateStatusAsync(new DiscordGame
     {
         Name       = "SDK | " + DiscordApi.Ping + "ms",
         StreamType = GameStreamType.Twitch,
         Url        = "https://twitch.tv/nathanferreiradsr_"
     });
 }
Exemple #7
0
        private Task Client_Ready(DSharpPlus.EventArgs.ReadyEventArgs e)
        {
            // let's log the fact that this event occured
            e.Client.DebugLogger.LogMessage(LogLevel.Info, "DBot", "Client is ready to process events.", DateTime.Now);

            // since this method is not async, let's return
            // a completed task, so that no additional work
            // is done
            return(Task.CompletedTask);
        }
Exemple #8
0
        private static Task Client_Ready(DiscordClient client, DSharpPlus.EventArgs.ReadyEventArgs e)
        {
            client.Logger.Log(LogLevel.Information, new EventId(700, "ClientReady"),
                              "Client ready!");

            client.Logger.Log(LogLevel.Information, new EventId(700, "ClientReady"),
                              $"Logged in as {client.CurrentUser.Username}#{client.CurrentUser.Discriminator} ({client.CurrentUser.Id})");

            return(Task.CompletedTask);
        }
Exemple #9
0
        private static Task Discord_Ready(DSharpPlus.EventArgs.ReadyEventArgs e)
        {
            Log("Client ready", Header: false);
            Log($"port is {port}");

            e.Client.DebugLogger.LogMessage(DSharpPlus.LogLevel.Info,
                                            "Splash",
                                            $"Client ready",
                                            DateTime.Now);
            return(Task.CompletedTask);
        }
Exemple #10
0
        private async Task _client_Ready(DSharpPlus.EventArgs.ReadyEventArgs e)
        {
            await Dispatcher.InvokeAsync(() =>
            {
                IsEnabled                  = true;
                loginGrid.Visibility       = Visibility.Collapsed;
                mainGrid.Visibility        = Visibility.Visible;
                guildsComboBox.ItemsSource = _client.Guilds.Values.OrderBy(g => g.Name);
            });

            foreach (DiscordGuild guild in _client.Guilds.Values)
            {
                Debug.WriteLine($"{guild.Name} - {guild.SplashUrl}");
            }
        }
Exemple #11
0
        private async Task Discord_Ready(DSharpPlus.EventArgs.ReadyEventArgs e)
        {
            var vault = new PasswordVault();

            vault.Add(new PasswordCredential(Constants.TOKEN_IDENTIFIER, _tokenId, _token));
            _token = null;

            if (_tokenId == "Default")
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    Frame.Navigate(typeof(DiscordPage));
                });
            }
        }
        private async Task Client_Ready(DiscordClient sender, DSharpPlus.EventArgs.ReadyEventArgs e)
        {
            // Okay now trust me here; I dont know WHY this needs to be run as its own Task in order for it to work
            // .......but it does.
            // Random bullshit, go!
            _ = Task.Run(async() =>
            {
                await Logger.Warning("Monitor", "Detected client reconnect; attempting channel check...");

                detectionService.Disable();

                await client.GetGuildAsync(channel.GuildId.Value, true);

                await channel.Guild.GetMemberAsync(client.CurrentUser.Id);

                await Client_VoiceStateUpdated(sender, null);
            });
        }
Exemple #13
0
 public static Task Discord_Ready(DiscordClient dc, DSharpPlus.EventArgs.ReadyEventArgs args)
 {
     _ = Task.Run(async() => {
         while (true)
         {
             foreach (var Status in Statuses)
             {
                 DiscordActivity activity = new DiscordActivity {
                     ActivityType = ActivityType.Playing,
                     Name         = Status
                 };
                 await dc.UpdateStatusAsync(activity, UserStatus.DoNotDisturb);
                 dc.Logger.LogInformation("Status Update");
                 await Task.Delay(120000);
             }
         }
     });
     return(Task.CompletedTask);
 }
Exemple #14
0
#pragma warning disable 1998
        private static async Task PClinet_Ready(DSharpPlus.EventArgs.ReadyEventArgs e)
        {
            pLobbyChannel = await(pClient.GetChannelAsync(XML_Config.pConfig.strLobbyChannelID).ConfigureAwait(false));
            if (pLobbyChannel == null)
            {
                Console.WriteLine($"Error pLobbyChannel == null");
            }

            if (XML_Config.pConfig.strLobbyChannelID == 0 ||
                string.IsNullOrEmpty(XML_Config.pConfig.strBootingMessage))
            {
                return;
            }

#if !DEBUG
            await(
                await pClient.GetChannelAsync(XML_Config.pConfig.strLobbyChannelID).ConfigureAwait(false))
            .SendMessageAsync(XML_Config.pConfig.strBootingMessage);
#endif
        }
        private async Task BotClient_Ready(DSharpPlus.EventArgs.ReadyEventArgs e)
        {
            BotClient.Ready -= BotClient_Ready;
            if (DiscordPlugin.Instance.Config.GlobalChannel != 0)
            {
                try
                {
                    var global = await BotClient.GetChannelAsync(DiscordPlugin.Instance.Config.GlobalChannel);

                    //var botMember = await global.Guild.GetMemberAsync(BotClient.CurrentUser.Id);
                    //if (!global.PermissionsFor(botMember).HasFlag(Permissions.SendMessages))
                    //    throw new Exception();
                }
                catch (Exception ex)
                {
                    Log.Error("Bot cannot access global chat channel! Discord setup cannot continue!");
                    await BotClient.DisconnectAsync();
                }
            }

            if (DiscordPlugin.Instance.Config.GlobalChannel != 0)
            {
                try
                {
                    var admin = await BotClient.GetChannelAsync(DiscordPlugin.Instance.Config.AdminChannel);

                    //var botMember = await admin.Guild.GetMemberAsync(BotClient.CurrentUser.Id);
                    //if (!admin.PermissionsFor(botMember).HasFlag(Permissions.SendMessages))
                    //    throw new Exception();
                }
                catch (Exception ex)
                {
                    Log.Error("Bot cannot access admin chat channel! Discord setup cannot continue!");
                    await BotClient.DisconnectAsync();
                }
            }

            Log.Info("Discord connected.");
        }
        public static Task Discord_Ready(DiscordClient dc, DSharpPlus.EventArgs.ReadyEventArgs args)
        {
            _ = Task.Run(async() => {
                dc.Logger.LogInformation("Looking for Reminders");
                var output = await SQLC.GetReminders();

                if (output.Any())
                {
                    foreach (var item in output)
                    {
                        long ID         = item.ID;
                        long ChannelID  = item.ChannelID;
                        long Date       = item.Date;
                        string Reminder = item.Reminder;

                        try {
                            DiscordGuild Guild     = await dc.GetGuildAsync(GuildID);
                            DiscordMember member   = await Guild.GetMemberAsync((ulong)ID);
                            DiscordChannel channel = Guild.GetChannel((ulong)ChannelID);
                            DateTime dateTime      = DateTime.FromBinary(Date);

                            if (dateTime < DateTime.Now)
                            {
                                await SQLC.DeleteRemindersWithDate(Date);
                                await channel.SendMessageAsync($":alarm_clock:, {member.Mention} you wanted me to remind you the following but I'm Late:\n\n{Reminder}");
                                continue;
                            }

                            _ = Task.Run(async() => {
                                await Task.Delay((int)dateTime.Subtract(DateTime.Now).TotalMilliseconds);

                                DiscordGuild Guild     = await dc.GetGuildAsync(GuildID);
                                DiscordMember member   = await Guild.GetMemberAsync((ulong)ID);
                                DiscordChannel channel = Guild.GetChannel((ulong)ChannelID);

                                await channel.SendMessageAsync($":alarm_clock:, {member.Mention} you wanted me to remind you the following:\n\n{Reminder}");

                                await SQLC.DeleteRemindersWithDate(Date);
                            });
                        } catch (Exception) {
                            await SQLC.DeleteRemindersWithDate(Date);
                            continue;
                        }
                    }
                    dc.Logger.LogInformation("Found Reminders and started them");
                }
                else
                {
                    dc.Logger.LogInformation("No Reminders found");
                }

                dc.Logger.LogInformation("Looking for muted Members");
                output = await SQLC.GetTempmutes();
                if (output.Any())
                {
                    foreach (var item in output)
                    {
                        long ID   = item.ID;
                        long Date = item.Date;

                        try {
                            DiscordGuild Guild    = await dc.GetGuildAsync(GuildID);
                            DiscordRole MutedRole = Guild.GetRole(Program.MutedRole);
                            DiscordMember member  = await Guild.GetMemberAsync((ulong)ID);
                            DateTime dateTime     = DateTime.FromBinary(Date);

                            if (dateTime < DateTime.Now)
                            {
                                await SQLC.DeleteTempmutesWithID(ID);
                                await member.RevokeRoleAsync(MutedRole);
                                continue;
                            }

                            _ = Task.Run(async() => {
                                try {
                                    await Task.Delay((int)dateTime.Subtract(DateTime.Now).TotalMilliseconds);

                                    DiscordGuild Guild    = await dc.GetGuildAsync(GuildID);
                                    DiscordRole MutedRole = Guild.GetRole(Program.MutedRole);
                                    DiscordMember member  = await Guild.GetMemberAsync((ulong)ID);

                                    var PS   = await SQLC.GetPlayer(member.Id);
                                    PS.Muted = false;
                                    await PS.Save();

                                    await member.RevokeRoleAsync(MutedRole);
                                    await SQLC.DeleteTempmutesWithID(ID);
                                } catch (Exception) {
                                    dc.Logger.LogInformation($"Failed the Tempmute process for {member.Username + member.Discriminator}");
                                }
                            });
                        } catch (Exception) {
                            await SQLC.DeleteTempmutesWithID(ID);
                            continue;
                        }
                    }
                    dc.Logger.LogInformation("Found muted Members and starting them");
                }
                else
                {
                    dc.Logger.LogInformation("No muted Members found");
                }

                while (true)
                {
                    foreach (var Status in Statuses)
                    {
                        DiscordActivity activity = new DiscordActivity {
                            ActivityType = ActivityType.Playing,
                            Name         = Status
                        };
                        await dc.UpdateStatusAsync(activity, UserStatus.DoNotDisturb);
                        dc.Logger.LogInformation("Status Update");
                        await Task.Delay(120000);
                    }
                }
            });
            return(Task.CompletedTask);
        }
 private Task Client_Ready(DSharpPlus.EventArgs.ReadyEventArgs e)
 {
     e.Client.DebugLogger.LogMessage(LogLevel.Info, "Wolfy", "Ready!", DateTime.Now);
     return(Task.CompletedTask);
 }
Exemple #18
0
 private Task Client_Ready(DiscordClient sender, DSharpPlus.EventArgs.ReadyEventArgs e)
 {
     return(Task.CompletedTask);
 }
Exemple #19
0
        private Task OnReady(DSharpPlus.EventArgs.ReadyEventArgs e)
        {
            TryGetChannel(_discordClient);

            return(Task.CompletedTask);
        }