public async Task Invite() { var user = (SocketGuildUser)Context.Message.Author; if (Xml.CommandAllowed("invite", Context) && user.Roles.Count > 1 && !user.Roles.Any(x => x.Id.Equals(UserSettings.Roles.LurkerRoleID(Context.Guild.Id)))) { //Create and link Invite var guildChan = (SocketTextChannel)Context.Channel; IInvite invite = await guildChan.CreateInviteAsync(86400, 1, true, true); IUserMessage msg = await Context.Channel.SendMessageAsync($"Your new invite link is ``{invite.Url}`` and it will expire in 24 hours. This message will be deleted in 7 seconds."); //Log which user created invite var botlog = await Context.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(Context.Guild.Id)); var embed = Embeds.LogCreateInvite((SocketGuildUser)Context.Message.Author, invite.Id); await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false); //Save Invite and Author UserID to XML doc to track var invites = Context.Guild.GetInvitesAsync().Result; JackFrostBot.UserSettings.Invites.Update(Context.Guild.Id, invites); //Delete message after 15 seconds await Task.Delay(TimeSpan.FromSeconds(7)).ContinueWith(__ => msg.DeleteAsync()); } }
public static Task DeleteAsync(this IInvite invite, IRestRequestOptions options = null, CancellationToken cancellationToken = default) { var client = invite.GetRestClient(); return(client.DeleteInviteAsync(invite.Code, options, cancellationToken)); }
public async Task Invite() { var invites = await Context.Guild.GetInvitesAsync(); IInvite invite = invites.FirstOrDefault(t => !t.IsTemporary); if (invite == null) { // TODO: call Context.Guild.DefaultChannel instead later on var defaultChannel = Context.Guild.TextChannels .OrderBy(c => c.Position) .FirstOrDefault(); if (defaultChannel == null) { await ReplyAsync("Sorry, žádný tu nemám :("); return; } invite = await defaultChannel.CreateInviteAsync(null); logger.LogInformation($"New invite '{invite.Url}' created by user '{Context.User.Id}'"); } await ReplyAsync(invite.Url); }
public InviteCreatedEventArgs( Optional <Snowflake> guildId, IInvite invite) { GuildId = guildId; Invite = invite; }
public async Task Davet() { IInvite davet = await(Context.Channel as IGuildChannel).CreateInviteAsync(); var eb = new EmbedBuilder() { Title = "Davet", Description = davet.Url, Color = Color.Blue }; await Context.Channel.SendMessageAsync("", false, eb); }
void LogEntry(IInvite invite, ChessPlayer player) { EmbedBuilder builder = new EmbedBuilder(); builder.Title = "Invite Created"; builder.WithCurrentTimestamp(); builder.AddField("For", player.Name, true); builder.AddField("Code", invite.Code, true); LogChnl(builder, SystemChannel); }
public async Task createInvite(string hi) { if (hi != "invite") { return; } IUser user = Context.User as IUser; if (DataManager.LandingChannel == 0) { await Context.Channel.SendMessageAsync(@"You must specify a landing channel first"); return; } ITextChannel chnl = Context.Guild.GetChannel(DataManager.LandingChannel) as ITextChannel; IInvite invite = await chnl.CreateInviteAsync(maxAge : null); await Context.Channel.SendMessageAsync( @"ᴡᴇʟᴄᴏᴍᴇ ᴛᴏ Lynx Modz Community ʜᴇʀᴇ ɪꜱ ᴡʜᴀᴛ ᴏᴜʀ ꜱᴇʀᴠᴇʀ ʜᴀꜱ ᴛᴏ ᴏꜰꜰᴇʀ: :sparkles:𝐆𝐚𝐦𝐢𝐧𝐠 𝐂𝐨𝐦𝐦𝐮𝐧𝐢𝐭𝐲 :sparkles:𝐃𝐚𝐢𝐥𝐲 𝐅𝐫𝐞𝐞 𝐆𝐭𝐚 𝐌𝐨𝐧𝐞𝐲 𝐃𝐫𝐨𝐩𝐬 :sparkles:𝐀𝐜𝐭𝐢𝐯𝐞 𝐎𝐰𝐧𝐞𝐫 𝐚𝐧𝐝 𝐒𝐭𝐚𝐟𝐟 :sparkles:𝐂𝐡𝐞𝐚𝐩 𝐑𝐞𝐜𝐨𝐯𝐞𝐫𝐲𝐬 :sparkles:𝐅𝐚𝐬𝐭 𝐀𝐧𝐝 𝐒𝐞𝐜𝐮𝐫𝐞 :sparkles:𝐅𝐫𝐞𝐪𝐮𝐞𝐧𝐭 𝐆𝐢𝐯𝐞𝐚𝐰𝐚𝐲𝐬 :sparkles:𝐒𝐢𝐦𝐩𝐥𝐞 𝐑𝐮𝐥𝐞𝐬 :sparkles:𝐏𝐫𝐨𝐨𝐟 𝐎𝐟 𝐎𝐮𝐫 𝐖𝐨𝐫𝐤 :sparkles:𝐆𝐓𝐀 𝐌𝐨𝐧𝐞𝐲 𝐟𝐨𝐫 𝐈𝐧𝐯𝐢𝐭𝐞𝐬 "); if (DataManager.InviteMap.ContainsKey(user.Id.ToString())) { var inviteId = DataManager.InviteMap[Context.User.Id.ToString()]; var thing = await chnl.GetInvitesAsync(); var realInvite = thing.Where(x => x.Id == inviteId).FirstOrDefault(); await Context.Channel.SendMessageAsync(realInvite.Url); } else { DataManager.InviteMap.Add(user.Id.ToString(), invite.Id); await Context.Channel.SendMessageAsync(invite.Url); } await Context.Channel.SendMessageAsync(@"https://tenor.com/view/line-rainbow-bar-gif-14589887"); }
/// <summary> /// Caches a value. Certain instance types may have specializations which cache more than one value from the /// instance. /// </summary> /// <param name="key">The cache key.</param> /// <param name="instance">The instance.</param> /// <typeparam name="TInstance">The instance type.</typeparam> public void Cache <TInstance>(object key, TInstance instance) where TInstance : class { Action cacheAction = instance switch { IWebhook webhook => () => CacheWebhook(key, webhook), ITemplate template => () => CacheTemplate(key, template), IIntegration integration => () => CacheIntegration(key, integration), IBan ban => () => CacheBan(key, ban), IGuildMember member => () => CacheGuildMember(key, member), IGuildPreview preview => () => CacheGuildPreview(key, preview), IGuild guild => () => CacheGuild(key, guild), IEmoji emoji => () => CacheEmoji(key, emoji), IInvite invite => () => CacheInvite(key, invite), IMessage message => () => CacheMessage(key, message), IChannel channel => () => CacheChannel(key, channel), _ => () => CacheInstance(key, instance) }; cacheAction(); }
public async Task <RuntimeResult> Setup(int count = 3) { IRole role = Context.Guild.Roles.FirstOrDefault(x => x.Name == TTTService.RoleName); if (role == null) { role = await Context.Guild.CreateRoleAsync(TTTService.RoleName, isMentionable : false); } var existing = Context.Guild.VoiceChannels.Count(x => x.Name.StartsWith("ttt-")); ICategoryChannel category = Context.Guild.CategoryChannels.FirstOrDefault(x => x.Name == "TTT"); if (category == null) { category = await Context.Guild.CreateCategoryChannelAsync("TTT"); await category.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, Program.NoPerms); await category.AddPermissionOverwriteAsync(role, Program.ReadPerms); } for (int i = 0; i < (count * count); i++) { IVoiceChannel vc = Context.Guild.VoiceChannels.FirstOrDefault(x => x.Name.StartsWith($"ttt-{i}")); if (vc == null) { vc = await Context.Guild.CreateVoiceChannelAsync($"ttt-{i}", x => { x.CategoryId = category.Id; }); } var invites = await vc.GetInvitesAsync(); IInvite invite = invites.FirstOrDefault(); if (invite == null) { invite = await vc.CreateInviteAsync(maxAge : null, maxUses : 1, isTemporary : true); } await vc.ModifyAsync(x => x.Name = $"ttt-{i}-{invite.Code}"); } return(Success("Server has been setup for tic tac toe.")); }
public static Task DeleteAsync(this IInvite invite, IRestRequestOptions options = null) { var client = invite.GetRestClient(); return(client.DeleteInviteAsync(invite.Code, options)); }
public async Task HandleCommand(SocketMessage messageParam) { SocketUserMessage message = messageParam as SocketUserMessage; bool isDM = await Functions.isDM(message as IMessage); if (isDM && Var.LockDM) { Console.WriteLine(message.Author.Username + " [" + message.Author.Id + "] attempted to use a command in DM's:\n'" + message.Content + "'"); return; } if (message == null) { return; } if (message.Author.Id == client.CurrentUser.Id) { return; //doesn't allow the bot to respond to itself } if (Var.DebugMode && message.Author.Id != Constants.Users.BRADY && Var.DebugUsers.Where(x => x.Id == message.Author.Id).Count() <= 0) { return; } if (!Var.DebugMode && message.Channel.Id == Constants.Channels.DEBUG) { return; } var user = Functions.GetUser(message.Author); #region Pre-Command Functions if (lastDay.DayOfYear < Var.CurrentDate().DayOfYear) { int strikeCount = (Var.CurrentDate() - Constants.Dates.STRIKE_END).Days; await client.SetGameAsync(strikeCount + " days since last strike", type : ActivityType.Watching); } //checks if message contains any blocked words if (!isDM && (message.Channel as IGuildChannel).Guild.Id == Constants.Guilds.YORK_UNIVERSITY && Functions.Filter(message.Content)) { await message.DeleteAsync(); return; } if (Var.blockedUsers.Where(x => x.Id == message.Author.Id).Count() > 0) { return; //prevents "blocked" users from using the bot } ulong[] blockedChannels = { Constants.Channels.GENERAL_SLOW, Constants.Channels.GENERAL_TRUSTED, Constants.Channels.NEWS_DEBATE, Constants.Channels.LIFESTYLE }; if (!isDM && (message.Channel as IGuildChannel).Guild.Id == Constants.Guilds.YORK_UNIVERSITY && (blockedChannels.Contains(message.Channel.Id)) && !(message.Author as IGuildUser).RoleIds.Contains(Constants.Roles.MOD) && !(message.Author as IGuildUser).RoleIds.Contains(Constants.Roles.BOOSTER)) { return; } if (message.Author.IsBot && message.Author.Id != Constants.Users.FORKPY) { return; } //present stuff if (Var.presentWaiting && message.Content == Convert.ToString(Var.presentNum)) { Var.presentWaiting = false; var presents = DBFunctions.GetItemIDList(); int presID; do { var presIndex = rdm.Next(presents.Count()); presID = presents[presIndex]; } while (!DBFunctions.ItemIsPresentable(presID)); Var.present = DBFunctions.GetItemName(presID); Var.rPresent = Var.present; var presentName = Var.present; var pMessage = DBFunctions.GetItemDescription(presID); var msg = $"{message.Author.Username}! You got...\nA {Func.ToTitleCase(presentName.Replace('_', ' '))}! {DBFunctions.GetItemEmote(presID)} {pMessage}"; user.GiveItem(Var.present); if (Var.replaceable) { msg += $"\nDon't like this gift? Press {Var.presentNum} again to replace it once!"; Var.replacing = true; Var.presentReplacer = message.Author; } await message.Channel.SendMessageAsync(msg); } else if (Var.replaceable && Var.replacing && message.Content == Convert.ToString(Var.presentNum) && message.Author == Var.presentReplacer) { if (user.HasItem(Var.present)) { user.RemoveItem(Var.present); await message.Channel.SendMessageAsync($":convenience_store: {DBFunctions.GetItemEmote(Var.present)} :runner: \nA **new** present appears! :gift: Press {Var.presentNum} to open it!"); Var.presentWaiting = true; Var.replacing = false; Var.replaceable = false; } else { await message.Channel.SendMessageAsync("You no longer have the present, so you cannot replace it!"); Var.replacing = false; Var.replaceable = false; } } //detects invites for unwanted servers (in yorku server) and deletes them if (!isDM && (message.Channel as IGuildChannel).Guild.Id == Constants.Guilds.YORK_UNIVERSITY && message.Content.ToLower().Contains("discord.gg") || message.Content.ToLower().Contains("discordapp.com/invite")) { var words = message.Content.Split(' '); foreach (string word in words) { if (word.Contains("discord")) { string id = word.Split('/')[word.Split('/').Count() - 1]; IInvite inv = await client.GetInviteAsync(id); if (inv.GuildId == Constants.Guilds.FORKU) { await messageParam.DeleteAsync(); } return; } } } #endregion int argPos = 0; //detect and execute commands if (message.HasCharPrefix(';', ref argPos)) { // new user prevention var userCreationDate = message.Author.CreatedAt; var existenceTime = DateTime.UtcNow.Subtract(userCreationDate.DateTime); var week = new TimeSpan(7, 0, 0, 0); if (existenceTime < week) { if (!newUsers.Contains(message.Author.Id)) { newUsers.Add(message.Author.Id); await message.Author.SendMessageAsync("Hi there! Welcome to Discord. In order to avoid bot abuse, your account must be older than a few days.\n" + "If you don't understand, just message <@108312797162541056> about it.\nThanks!"); } return; } var context = new CommandContext(client, message); var result = await commands.ExecuteAsync(context, argPos, services : null); if (!result.IsSuccess) { if (result.Error != CommandError.UnknownCommand) { Console.WriteLine(result.ErrorReason); var emb = new InfoEmbed("ERROR:", result.ErrorReason).Build(); await message.Channel.SendMessageAsync("", embed : emb); } else { if (user.HasItem(message.Content.Replace(";", ""))) { await message.Channel.SendMessageAsync("Nothing happens... *Use `;suggest [suggestion]` if you have an idea for this item!*"); } } } else { //give user a chance at a lootbox bool inLM = false; //go through users last command time foreach (var u in Var.lastMessage) { //ensure user is in dictionary if (u.Key == context.User.Id) { inLM = true; break; } } if (inLM == false) { Var.lastMessage.Add(context.User.Id, Var.CurrentDate() - new TimeSpan(1, 0, 1)); } //if chance of lootbox if (Var.lastMessage[context.User.Id] <= Var.CurrentDate() - new TimeSpan(1, 0, 0)) { //10% chance at lootbox if (rdm.Next(100) + 1 < 10) { await context.Channel.SendMessageAsync(":package: `A lootbox appears in your inventory! (package)`"); Functions.GetUser(context.User).GiveItem("package"); } } //set last message time to now Var.lastMessage[context.User.Id] = Var.CurrentDate(); } } else if (message.MentionedUsers.First().Id == client.CurrentUser.Id && message.Author.Id != client.CurrentUser.Id && Var.responding && ((message.Channel as IGuildChannel).Guild.Id != Constants.Guilds.YORK_UNIVERSITY || message.Channel.Id == Constants.Channels.COMMANDS || message.Channel.Id == 265998661606047744)) { Functions.Respond(message); } else if ((message.Channel as IGuildChannel).Guild.Id != Constants.Guilds.YORK_UNIVERSITY && !Var.responding) { Functions.Respond(message); } else { return; } }
/// <summary> /// Converts an existing <see cref="IInvite"/> to an abstracted <see cref="IInvite"/> value. /// </summary> /// <param name="invite">The existing <see cref="IInvite"/> to be abstracted.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="invite"/>.</exception> /// <returns>An <see cref="IInvite"/> that abstracts <paramref name="invite"/>.</returns> public static IInvite Abstract(this IInvite invite) => invite switch { null => throw new ArgumentNullException(nameof(invite)),
public async Task Deliver(int id) { if (id > 0) { if (SS.toBeDelivered.Contains(id)) { if (SS.activeOrders.FirstOrDefault(s => s.Value.Id == id).Value != null) { Chef c = SS.chefList.FirstOrDefault(a => a.Value.ChefId == Context.User.Id).Value; Sandwich order = SS.activeOrders.FirstOrDefault(s => s.Value.Id == id).Value; if (order.Status == OrderStatus.ReadyToDeliver) { try { Console.WriteLine("passed finish"); await ReplyAsync("DMing you an invite! Go deliver it! Remember to be nice and ask for `;feedback`"); IGuild s = await Context.Client.GetGuildAsync(order.GuildId); ITextChannel ch = await s.GetTextChannelAsync(order.ChannelId); IGuildUser u = await s.GetUserAsync(order.UserId); IDMChannel dm = await u.CreateDMChannelAsync(); await dm.SendMessageAsync($"Your sandwich is being delivered soon! Watch out!"); IInvite inv = await ch.CreateInviteAsync(0, 1, false, true); IDMChannel artistdm = await Context.User.CreateDMChannelAsync(); var builder = new EmbedBuilder(); builder.ThumbnailUrl = order.AvatarUrl; builder.Title = $"Your order is being delivered by {Context.User.Username}#{Context.User.Discriminator}!"; var desc = $"```{order.Desc}```\n" + $"**Incoming sandwich! Watch {order.GuildName}!**"; builder.Description = desc; builder.Color = new Color(163, 198, 255); builder.WithFooter(x => { x.IconUrl = u.GetAvatarUrl(); x.Text = $"Ordered at: {order.date}."; }); builder.Timestamp = DateTime.UtcNow; await artistdm.SendMessageAsync(inv.ToString()); SS.cache.Add(order); order.Status = OrderStatus.Delivered; SS.toBeDelivered.Remove(order.Id); SS.activeOrders.Remove(order.Id); SS.hasAnOrder.Remove(order.UserId); c.ordersDelivered += 1; //await e.Channel.SendMessage("The Order has been completed and removed from the system. You cannot go back now!"); SS.Save(); } catch (Exception ex) { await ReplyAsync(":ghost:"); await ReplyAsync($"```{ex}```"); return; } } else { await ReplyAsync($"This order is not ready to be delivered just yet! It is currently Order Status {order.Status}"); return; } } else { await ReplyAsync("Invalid order probably (tell Fires its a problem with the checky thingy, the thing thing)"); return; } } else { await ReplyAsync("You are not high enough rank to deliver orders!"); return; } } else { await ReplyAsync("This order is not ready to be delivered yet! (this error can also occur if you are not using the right id)"); return; } }
public static async Task DeleteAsync(IInvite invite, BaseDiscordClient client, RequestOptions options) { await client.ApiClient.DeleteInviteAsync(invite.Code, options).ConfigureAwait(false); }
public async Task Deliver(string id) { _SS.Save(); using (Context.Channel.EnterTypingState()) { Sandwich o = await _DB.FindOrder(id); if (o.ArtistId == Context.User.Id) { if (o.Status == OrderStatus.ReadyToDeliver) { Artist a = await _ADB.FindArtist(Context.User.Id); //Collect variables await ReplyAsync($"{Context.User.Mention} DMing you an invite! Go deliver it! Remember to be nice and ask for `;feedback`."); IGuild s = await Context.Client.GetGuildAsync(o.GuildId); SandwichUser user = await _UDB.FindUser(o.UserId); await _UDB.UpOrders(user.Id); ITextChannel ch = await s.GetTextChannelAsync(o.ChannelId); IGuildUser u = await s.GetUserAsync(o.UserId); IDMChannel dm = await u.GetOrCreateDMChannelAsync(); //Create Invite IInvite inv = await ch.CreateInviteAsync(1800, 1, false, true); IDMChannel artistdm = await Context.User.GetOrCreateDMChannelAsync(); //Build embed var builder = new EmbedBuilder(); builder.ThumbnailUrl = o.AvatarUrl; builder.Title = $"Your order is being delivered by {Context.User.Username}#{Context.User.Discriminator}!"; var desc = $"```{o.Desc}```\n" + $"**Incoming sandwich! Watch {o.GuildName}!**"; builder.Description = desc; builder.Color = new Color(255, 181, 10); builder.WithFooter(x => { x.IconUrl = u.GetAvatarUrl(); x.Text = $"Ordered at: {o.date}."; }); builder.Timestamp = DateTime.UtcNow; await dm.SendMessageAsync($"Your sandwich is being delivered soon! Watch out!", embed : builder); //Finish up await artistdm.SendMessageAsync("Invite: " + inv.ToString() + " \r\n Name: " + o.UserName); o.Status = OrderStatus.Delivered; await _ADB.UpdateMostRecentOrder(a); await _UDB.GiveUserCredits(Context.User as IGuildUser, 5.0f); await _DB.DelOrder(id); } else { await ReplyAsync("This order is not ready to be delivered yet."); } } else { await ReplyAsync("You have not claimed this order!"); } } }