private ulong usrlogcID = 287990510428225537; //287990510428225537 306909741622362112 public async Task Start() { // Define the DiscordSocketClient client = new DiscordSocketClient(); var token = "Mshitlol" client.Log += async(message) => { await Log(message); }; client.JoinedGuild += async(m) => { IGuild usr = client.GetGuild(usrID); ITextChannel usrc = await usr.GetTextChannelAsync(usrlogcID); await usrc.SendMessageAsync($":slight_smile: I have joined `{m.Name}`(`{m.Id}`), I am now in {client.Guilds.Count} servers!"); await m.DefaultChannel.SendMessageAsync("Hi I am **Sandwich Delivery Bot**.Thank you for choosing our bot! To order a Sandwich, type `;order extra large blt`. For the list of commands, we have `;help`. If you wish to contact us, please use `; server`. \r\n **Please understand that when you order, you will recieve what you ordered from a *****real*****person. They have feelings.**"); if (!m.CurrentUser.GuildPermissions.CreateInstantInvite) { await m.DefaultChannel.SendMessageAsync(":warning: The bot cannot create instant invites! Please give the bot permission or else it will not work! :warning: "); } }; client.LeftGuild += async(m) => { IGuild usr = client.GetGuild(usrID); ITextChannel usrc = await usr.GetTextChannelAsync(usrlogcID); await usrc.SendMessageAsync($":slight_frown: I have left `{m.Name}`(`{m.Id}`), I am now in {client.Guilds.Count} servers..."); }; client.MessageReceived += async(m) => { if (m.Author.IsBot) { return; } if (m.Channel.Id == client.CurrentUser.Id) { return; } if (m.MentionedUsers.Any(u => u.Id == client.CurrentUser.Id)) { if (m.Content.Contains("help")) { await m.Channel.SendMessageAsync("Type `;help`. `;server` if you have any problems."); } } var rnd = new Random(); var r = rnd.Next(1, 25); if (r == 2) { var totalChannels = 0; var totalUsers = 0; foreach (var obj in client.Guilds) { totalChannels = totalChannels + obj.Channels.Count; totalUsers = totalUsers + obj.Users.Count; } await client.SetGameAsync($"In {totalChannels} channels with a total of {totalUsers} users! | Type ;motd for help!"); } if (r == 6) { await client.SetGameAsync($"In {client.Guilds.Count()} servers! | Type ;motd for help!"); } }; ss = new SandwichService(); ss.Load(); foreach (var obj in ss.activeOrders) { if (obj.Value.Status == OrderStatus.ReadyToDeliver) { ss.toBeDelivered.Add(obj.Value.Id); Console.WriteLine($"Added order {obj.Value.Id} to toBeDelivered."); } } // Login and connect to Discord. var map = new DependencyMap(); map.Add(client); handler = new CommandHandler(); map.Add(ss); await handler.Install(map); await client.LoginAsync(TokenType.Bot, token); await client.StartAsync(); // Block this program until it is closed. await Task.Delay(-1); }
public async Task Start() { // Define the DiscordSocketClient client = new DiscordSocketClient(); var token = "nope. Bad idea that I stored it in plaintext tho lol."; ss = new SandwichService(); client.Log += async(message) => { await Log(message); }; client.JoinedGuild += async(m) => { IGuild usr = client.GetGuild(ss.USRGuildId); ITextChannel usrc = await usr.GetTextChannelAsync(ss.LogId); var e = new EmbedBuilder(); e.Color = new Color(94, 180, 255); e.ThumbnailUrl = m.IconUrl; e.Timestamp = DateTime.Now; e.Description = $"I have joined **{m.Name}**(`{m.Id}`) \r\n" + $"That is **{m.Users.Count}** new users. \r\n" + $"I am now in **{client.Guilds.Count}** servers!"; await usrc.SendMessageAsync("", embed : e); var textchannel = m.GetTextChannel(m.Channels.Where(c => m.CurrentUser.GetPermissions(c).SendMessages) .OrderBy(c => c.Position) .FirstOrDefault().Id); ss.Load(); await textchannel.SendMessageAsync(ss.motd); await bdb.NewGuild(m.Id, textchannel.Id); await bdb.SaveChangesAsync(); if (!m.CurrentUser.GuildPermissions.CreateInstantInvite) { await m.DefaultChannel.SendMessageAsync(":warning: The bot cannot create instant invites! Please give the bot permission or else it will not work! :warning: "); } }; client.LeftGuild += async(m) => { await bdb.RemoveGuild(m.Id); IGuild usr = client.GetGuild(ss.USRGuildId); ITextChannel usrc = await usr.GetTextChannelAsync(ss.LogId); var e = new EmbedBuilder(); e.Color = new Color(232, 34, 34); e.ThumbnailUrl = m.IconUrl; e.Timestamp = DateTime.Now; e.Description = $"I have left **{m.Name}**(`{m.Id}`)! \r\n" + $"That is **{m.Users.Count}** less users. \r\n" + $"I am now in **{client.Guilds.Count}** servers..."; await usrc.SendMessageAsync("", embed : e); }; client.MessageReceived += async(m) => { if (m.Author.IsBot) { return; } if (m.Channel.Id == client.CurrentUser.Id) { return; } if (m.MentionedUsers.Any(u => u.Id == client.CurrentUser.Id)) { if (m.Content.Contains("help")) { await m.Channel.SendMessageAsync("Type `;help`. `;server` if you have any problems."); } } var rnd = new Random(); var r = rnd.Next(1, 25); if (r == 2) { var totalChannels = 0; var totalUsers = 0; foreach (var obj in client.Guilds) { totalChannels = totalChannels + obj.Channels.Count; totalUsers = totalUsers + obj.Users.Count; } await client.SetGameAsync($"{totalChannels} channels with a total of {totalUsers} users. | Type ;motd for help"); } if (r == 6) { await client.SetGameAsync($" {client.Guilds.Count()} servers. | Type ;motd for help"); } }; var serviceProvider = ConfigureServices(); //var timer = new System.Threading.Timer(async (e) => //{ // await VerifyTransactionsAsync(); //}, null, 0, (int)TimeSpan.FromMinutes(0.5).TotalMilliseconds); // Login and connect to Discord. handler = new CommandHandler(); await handler.Install(serviceProvider); await client.LoginAsync(TokenType.Bot, token); await client.StartAsync(); // Block this program until it is closed. await Task.Delay(-1); }