public NowPlayingInterface() { display = new Embed (); display.Show (); ServiceManager.PlayerEngine.EngineBeforeInitialize += engine => { var clutter_engine = ServiceManager.PlayerEngine.ActiveEngine as ISupportClutter; if (clutter_engine == null) { throw new ApplicationException ("Banshee GStreamer engine does not have Clutter support"); } video_texture = new Texture () { SyncSize = false }; clutter_engine.EnableClutterVideoSink (video_texture.Handle); }; ServiceManager.SourceManager.SourceAdded += OnSourceAdded; }
public static RollResult DiceRoll(Embed embed) => new RollResult(embed);
public async Task <IUserMessage> SendPlayerMessage(Embed embeddedContent, ulong discordId) { var message = await _discord.GetUser(discordId).SendMessageAsync(embed: embeddedContent); return(message); }
public async Task <ButtonComponent> SelectButtonAsync(ComponentBuilder builder, string text = null, Embed embed = null, bool deleteWhenDone = false, TimeSpan?timeout = null, AllowedMentions allowedMentions = null) { if (string.IsNullOrWhiteSpace(text) && embed == null) { throw new ArgumentNullException($"One of {nameof(text)} or {nameof(embed)} must be non-null"); } var selectionSource = new TaskCompletionSource <ButtonComponent>(); var selectionTask = selectionSource.Task; var timeoutTask = Task.Delay(timeout ?? InteractivityService.DefaultTimeout); var components = builder.Build(); var message = await ReplyAsync(message : text, embed : embed, component : components, allowedMentions : allowedMentions).ConfigureAwait(false); async Task CheckButtonAsync(CallbackEventArgs e) { if (e.User.Id != Context.User.Id) { return; } var btn = getButton(components, e.ComponentId); selectionSource.SetResult(btn); } try { ComponentService.Register(message, CheckButtonAsync, doSave: false); var task_result = await Task.WhenAny(timeoutTask, selectionTask).ConfigureAwait(false); var result = task_result == selectionTask ? await selectionTask.ConfigureAwait(false) : null; if (deleteWhenDone) { await message.DeleteAsync().ConfigureAwait(false); } else { // disable the buttons instead var disabledBuilder = new ComponentBuilder(); int i = 0; foreach (var row in builder.ActionRows) { foreach (var btn in row.Components) { disabledBuilder.WithButton(btn.Label, btn.CustomId, btn.Style, btn.Emote, btn.Url, true, i); } i++; } await message.ModifyAsync(x => { x.Components = disabledBuilder.Build(); }); } return(result); } finally { ComponentService.Unregister(message); } }
public async Task InviteCmd() { Embed e = _lib.CreateEmbedWithText("Invite Link", _core.GetInviteLink() + "\nThanks for inviting EdgyBot! :smile:"); await ReplyAsync("", embed : e); }
public async Task <IUserMessage> SendMessageAsync(ulong channel, string message, Embed embed = null) { return(await SendMessageAsync(GetChannel(channel), message, embed)); }
public static Task <RestUserMessage> InlineReplyAsync(this SocketMessage message, string text, bool isTTS, Embed embed, CancellationToken cancellationToken) => InlineReplyAsync(message, text, isTTS, embed, null, new RequestOptions { CancelToken = cancellationToken });
// inline replies public static Task <RestUserMessage> InlineReplyAsync(this SocketCommandContext message, string text = null, bool isTTS = false, Embed embed = null, AllowedMentions mentions = null, RequestOptions options = null) => InlineReplyAsync(message.Message, text, isTTS, embed, mentions, options);
public async Task <IUserMessage> HandleNewPaginatedMessageAsync(SocketCommandContext context, IEnumerable <EmbedField> displayFields, IEnumerable <string> displayTexts, Embed embed) { var message = await context.Channel.SendMessageAsync("", false, embed); var paginatedMessage = new PaginatedMessage() { DiscordMessageId = message.Id, DiscordChannelId = message.Channel.Id, DiscordUserId = context.User.Id, }; if (displayFields == null) { paginatedMessage.DisplayMessages = displayTexts.ToArray(); } else { paginatedMessage.DisplayFields = displayFields.ToArray(); } _activeMessages.Add(paginatedMessage); if (paginatedMessage.TotalPages == 1) { return(message); } await AddPaginatorReactionsAsync(message); AddNewTimer(message.Id); return(message); }
/// <summary> /// Sends a reply to a message in the same channel. /// </summary> /// <param name="message">The message to reply to.</param> /// <param name="embed">The embed message to send.</param> public static void SendReply(SocketMessage message, Embed embed) { message.Channel.SendMessageAsync(embed: embed).Wait(); }
public Task <RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options);
async Task <IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options) => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false);
protected async Task <IUserMessage> SendEmbedAsync(Embed embed) { return(await Context.Channel.SendMessageAsync("", false, embed)); }
protected async Task <IUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTts = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) { return(await Context.Channel.SendFileAsync(stream, filename, text, isTts, embed, options, isSpoiler)); }
internal void Update(API.Message model) { if (model.Attachments != null) { Attachments = model.Attachments.Select(x => new Attachment { Id = x.Id, Url = x.Url, ProxyUrl = x.ProxyUrl, Size = x.Size, Filename = x.Filename, Width = x.Width, Height = x.Height }).ToArray(); } else Attachments = new Attachment[0]; if (model.Embeds != null) { Embeds = model.Embeds.Select(x => { var embed = new Embed { Url = x.Url, Type = x.Type, Description = x.Description, Title = x.Title }; if (x.Provider != null) { embed.Provider = new EmbedReference { Url = x.Provider.Url, Name = x.Provider.Name }; } if (x.Author != null) { embed.Author = new EmbedReference { Url = x.Author.Url, Name = x.Author.Name }; } if (x.Thumbnail != null) { embed.Thumbnail = new File { Url = x.Thumbnail.Url, ProxyUrl = x.Thumbnail.ProxyUrl, Width = x.Thumbnail.Width, Height = x.Thumbnail.Height }; } return embed; }).ToArray(); } else Embeds = new Embed[0]; IsMentioningEveryone = model.IsMentioningEveryone; IsTTS = model.IsTextToSpeech; MentionIds = model.Mentions?.Select(x => x.Id)?.ToArray() ?? new string[0]; IsMentioningMe = MentionIds.Contains(_client.CurrentUserId); RawText = model.Content; _cleanText = null; Timestamp = model.Timestamp; EditedTimestamp = model.EditedTimestamp; if (model.Author != null) UserId = model.Author.Id; }
protected async Task <IUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false) { return(await Context.Channel.SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler)); }
public async Task LogAction(string action, bool logToFile = true, bool logToChannel = true, Embed embed = null) { if (logToChannel) { var channel = _client.GetChannel(_settings.BotAnnouncementChannel.Id) as ISocketMessageChannel; await channel.SendMessageAsync(action, false, embed); } if (logToFile) { File.AppendAllText(_settings.ServerRootPath + @"/log.txt", $"[{DateTime.Now:d/M/yy HH:mm:ss}] {action} {Environment.NewLine}"); } }
public static Task <RestUserMessage> InlineReplyAsync(this SocketCommandContext message, string text, bool isTTS, Embed embed, AllowedMentions mentions, CancellationToken cancellationToken) => InlineReplyAsync(message.Message, text, isTTS, embed, mentions, new RequestOptions { CancelToken = cancellationToken });
protected void SendGameMsg(string msg, Embed embed) { Channel.SendMessageAsync(msg, embed: embed).GetAwaiter().GetResult(); }
public static Task <RestUserMessage> InlineReplyAsync(this SocketMessage message, string text = null, bool isTTS = false, Embed embed = null, AllowedMentions mentions = null, RequestOptions options = null) => message.Channel.SendMessageAsync(text, isTTS, embed, options, mentions, new MessageReference(message.Id, message.Channel?.Id, (message.Channel as IGuildChannel)?.GuildId));
public async Task ProcessCommandAsync(SocketMessage msg) { var message = msg as SocketUserMessage; if (message == null) { return; } int argPos = 0; var context = new SocketCommandContext(Client, message); List <DiscordCustomPrefix> guildPrefixes = await PrefixService.GetGuildPrefixes(context.Guild); string FinalPrefix = Config.Prefix; foreach (DiscordCustomPrefix prefix in guildPrefixes) { argPos = 0; if (message.HasStringPrefix(prefix.Prefix, ref argPos)) { FinalPrefix = prefix.Prefix; break; } argPos = 0; } if (message.HasStringPrefix(FinalPrefix, ref argPos)) { string commandExecuted = message.Content.Split(' ')[0].Replace(FinalPrefix, ""); if (!Provider.GetService <CooldownService>().IsCooldownExpired(context.Guild.Id, commandExecuted)) { CommandInfo cmdInfo = Commands.FindInfoByName(commandExecuted); Embed cooldownEmbed = Provider.GetService <EmbedService>().MakeFailFeedbackEmbed($"The command `{cmdInfo.Name}` cannot be used for another {Math.Max(Provider.GetService<CooldownService>().GetRemainingTime(context.Guild.Id, cmdInfo), 1)} seconds!"); await context.Channel.SendMessageAsync(cooldownEmbed, lifeTime : Provider.GetService <Config>().FeedbackMessageLifeTime); return; } var result = await Commands.ExecuteAsync(context, argPos, Provider); if (result.IsSuccess) { CommandInfo cmdInfo = Commands.FindInfoByName(commandExecuted); if (cmdInfo != null) { foreach (var attr in cmdInfo.Preconditions) { if (attr.GetType() == typeof(RequireCooldownAttribute)) { RequireCooldownAttribute cooldownAttr = attr as RequireCooldownAttribute; Provider.GetService <CooldownService>().SetCooldown(context.Guild.Id, cmdInfo, cooldownAttr.Seconds); } } using (BotDBContext DBContext = Provider.GetService <DBContextFactory>().Create <BotDBContext>()) { string arguments = message.Content.Replace($"{FinalPrefix}{commandExecuted} ", "").Replace($"{FinalPrefix}{commandExecuted}", ""); DBContext.CommandLogs.Add(new DiscordCommandLog(message.Author.Id.ToString(), cmdInfo.Name, arguments, context.Channel.Id.ToString(), context.Guild.Id.ToString(), DateTime.Now)); await DBContext.SaveChangesAsync(); } } } else { ConsoleEx.WriteColoredLine(LogSeverity.Error, ConsoleTextFormat.TimeAndText, ConsoleColor.Red, $"[Command Error - {result.Error?.ToString()}] ", ConsoleColor.White, result.ErrorReason?.ToString()); int lifeTime = Provider.GetService <Config>().FeedbackMessageLifeTime; EmbedService embedService = Provider.GetService <EmbedService>(); switch (result.Error?.ToString()) { case "UnmetPrecondition": Embed unmetEmbed = embedService.MakeFailFeedbackEmbed(result.ErrorReason); await context.Channel.SendMessageAsync("", embed : unmetEmbed, lifeTime : lifeTime); break; case "UnknownCommand": string err = ""; err = result.ErrorReason?.ToString(); bool badArgs = (err.Contains("This input does not match any overload.")); if (badArgs) { await TriggerBadArgEmbed(commandExecuted, context, FinalPrefix); return; } List <FuzzyMatch> matches = Commands.FuzzySearch(commandExecuted); if (matches.Count > 0) { string builtString = ""; foreach (FuzzyMatch match in matches) { builtString += $"{match.TextValue.Bold()}, "; } builtString = builtString.Substring(0, builtString.Length - 2); Embed suggestEmbed = embedService.MakeFeedbackEmbed($"That command wasn't found.\nDid you mean {builtString}?"); await context.Channel.SendMessageAsync("", embed : suggestEmbed); } break; case "BadArgCount": await TriggerBadArgEmbed(commandExecuted, context, FinalPrefix); break; case "ParseFailed": Embed badParseEmbed = embedService.MakeFailFeedbackEmbed("Failed to parse one of the arguments for that command."); await context.Channel.SendMessageAsync("", embed : badParseEmbed, lifeTime : lifeTime); break; case "MultipleMatches": Embed multiMatchEmbed = embedService.MakeFailFeedbackEmbed("Multiple matches were found."); await context.Channel.SendMessageAsync("", embed : multiMatchEmbed, lifeTime : lifeTime); break; case "ObjectNotFound": Embed notFoundEmbed = embedService.MakeFailFeedbackEmbed("One of your specified objects could not be found."); await context.Channel.SendMessageAsync("", embed : notFoundEmbed, lifeTime : lifeTime); break; } } } else if (message.HasMentionPrefix(Provider.GetService <DiscordSocketClient>().CurrentUser, ref argPos)) { using (var typingState = message.Channel.EnterTypingState()) { string query = message.Content.Replace(Provider.GetService <DiscordSocketClient>().CurrentUser.Mention + " ", ""); string resp = await CleverbotAPI.AskAsync(query); await message.Channel.SendMessageAsync(resp); typingState.Dispose(); } } }
public async Task <IUserMessage> SendMessageAsync(IMessageChannel channel, string message, Embed embed = null) { try { return(await channel.SendMessageAsync(message, false, embed)); } catch (HttpException ex) { if (ex.DiscordCode == 50013) { await LogHelper.LogError($"The bot don't have rights to send message to {channel.Id} ({channel.Name}) channel!"); } throw; } }
private async Task <IUserMessage> RespondAsync(SocketUserMessage message, string response, Embed embedResponse = null, bool bypassEdit = false, bool rateLimitChecked = false) { SocketGuild guild = (message.Channel as SocketGuildChannel)?.Guild; if (!rateLimitChecked) { this.Throttler.Increment(message.Author.Id.ToString(), ThrottleType.User); if (guild != null) { this.Throttler.Increment(guild.Id.ToString(), ThrottleType.Guild); } } var props = new Dictionary <string, string> { { "server", guild?.Id.ToString() ?? "private" }, { "channel", message.Channel.Id.ToString() }, }; this.TrackEvent("messageSent", props); response = response.SubstringUpTo(Discord.DiscordConfig.MaxMessageSize); if (!bypassEdit && this.botResponsesCache.Get(message.Id) is IUserMessage oldMsg) { try { await oldMsg.ModifyAsync((m) => { m.Content = response; m.Embed = embedResponse; }); } catch (HttpException ex) when(ex.DiscordCode == 10008) { // ignore unknown messages; likely deleted } return(null); } else { return(await message.Channel.SendMessageAsync(response, false, embedResponse)); } }
public async Task <IUserMessage> ReplyAndDeleteAsync(SocketCommandContext context, string content, bool isTTS = false, Embed embed = null, TimeSpan?timeout = null, RequestOptions options = null) { timeout = timeout ?? _defaultTimeout; var message = await context.Channel.SendMessageAsync(content, isTTS, embed, options).ConfigureAwait(false); _ = Task.Delay(timeout.Value) .ContinueWith(_ => message.DeleteAsync().ConfigureAwait(false)) .ConfigureAwait(false); return(message); }
private async Task <IUserMessage> RespondAsync(SocketUserMessage message, string response, Embed embedResponse = null, bool bypassEdit = false) { var props = new Dictionary <string, string> { { "server", (message.Channel as SocketGuildChannel)?.Guild.Id.ToString() ?? "private" }, { "channel", message.Channel.Id.ToString() }, }; this.TrackEvent("messageSent", props); response = response.Substring(0, Math.Min(response.Length, 2000)); if (!bypassEdit && this.botResponsesCache.Get(message.Id) is IUserMessage oldMsg) { await oldMsg.ModifyAsync((m) => { m.Content = response; m.Embed = embedResponse; }); return(null); } else { return(await message.Channel.SendMessageAsync(response, false, embedResponse)); } }
public async Task <string> SelectButtonAsync(IEnumerable <string> options, string text = null, Embed embed = null, bool deleteWhenDone = false, TimeSpan?timeout = null) { var builder = new ComponentBuilder(); for (int i = 0; i < options.Count(); i++) { builder.WithButton(ButtonBuilder.CreatePrimaryButton(options.ElementAt(i), i.ToString())); } var btn = await SelectButtonAsync(builder, text, embed, deleteWhenDone, timeout).ConfigureAwait(false); return(options.ElementAt(int.Parse(btn.CustomId))); }
public static async Task <IUserMessage> MsgReplyEmbedAsync(this SocketCommandContext context, Embed emb, bool disalbeMention = true) { return(await context.Message.ReplyAsync(embed : emb, allowedMentions : disalbeMention?AllowedMentions.None : null)); }
public RollResult(Embed embed) : base(null, null) { RollEmbed = embed; }
public async Task WoodcuttingLevel() { //Okay let's get the User Woodcutting wc; using (var uow = DBHandler.UnitOfWork()) { wc = uow.Woodcutting.GetOrCreateWoodcutting(Context.User.Id); } //New list of stuff Dictionary <string, int> CutLogs = new Dictionary <string, int>() { { "Achey", wc.AcheyTrees }, { "Arctic Pine", wc.ArcticTrees }, { "Hollow", wc.HollowTrees }, { "Magic", wc.MagicTrees }, { "Mahogany", wc.MahoganyTrees }, { "Maple", wc.MapleTrees }, { "Normal", wc.NormalTrees }, { "Oak", wc.OakTrees }, { "Redwood", wc.RedwoodTrees }, { "Sulliuscep", wc.SullTrees }, { "Teak", wc.TeakTrees }, { "Yew", wc.YewTrees } }; //List sorted List <KeyValuePair <string, int> > logList = CutLogs.ToList(); logList = logList.OrderByDescending(x => x.Value).ToList(); //What's their axe level string axetype = ""; foreach (int key in AxeLevel.Keys) { if (axetype != "") { break; } else if (wc.Level >= key) { axetype = AxeLevel[key]; } } EmbedBuilder emb = new EmbedBuilder().WithTitle($"Wooductting XP | User: {Context.User.Username}").WithOkColour().WithDescription($"Level: {wc.Level} | Total XP: {wc.XP} | Axe Type: {axetype}"); EmbedFieldBuilder embF = new EmbedFieldBuilder().WithName("Amount of Logs Chopped"); string str = ""; foreach (KeyValuePair <string, int> Tree in logList) { str += $"{Tree.Key} trees: {Tree.Value}\n"; } str += $"\nTotal Logs: {CutLogs.Sum(x => x.Value)}"; embF = embF.WithValue(str); //Add to emb Embed embdone = emb.AddField(embF).Build(); //Send await Context.Channel.BlankEmbedAsync(embdone); }
public static bool TryParseOptionalElement(MrssOptionalElements optionalElements, XmlReader reader) { var parsed = false; try { switch (reader.LocalName) { case Community.ELEMENT_NAME: optionalElements.CommunityNode = new Community(); optionalElements.CommunityNode.ReadXml(reader); parsed = true; break; case Comments.ELEMENT_NAME: optionalElements.CommentsNode = new Comments(); optionalElements.CommentsNode.ReadXml(reader); parsed = true; break; case Responses.ELEMENT_NAME: optionalElements.ResponsesNode = new Responses(); optionalElements.ResponsesNode.ReadXml(reader); parsed = true; break; case Backlinks.ELEMENT_NAME: optionalElements.BacklinksNode = new Backlinks(); optionalElements.BacklinksNode.ReadXml(reader); parsed = true; break; case Embed.ELEMENT_NAME: var embedNode = new Embed(); embedNode.ReadXml(reader); if (optionalElements.EmbedNodes == null) optionalElements.EmbedNodes = new List<Embed>(); optionalElements.EmbedNodes.Add(embedNode); parsed = true; break; case Price.ELEMENT_NAME: optionalElements.PriceNode = new Price(); optionalElements.PriceNode.ReadXml(reader); parsed = true; break; case License.ELEMENT_NAME: optionalElements.LicenseNode = new License(); optionalElements.LicenseNode.ReadXml(reader); parsed = true; break; case PeerLink.ELEMENT_NAME: optionalElements.PeerLinkNode = new PeerLink(); optionalElements.PeerLinkNode.ReadXml(reader); parsed = true; break; case SubTitle.ELEMENT_NAME: optionalElements.SubTitleNode = new SubTitle(); optionalElements.SubTitleNode.ReadXml(reader); parsed = true; break; case Restriction.ELEMENT_NAME: optionalElements.RestrictionNode = new Restriction(); optionalElements.RestrictionNode.ReadXml(reader); parsed = true; break; case Status.ELEMENT_NAME: optionalElements.StatusNode = new Status(); optionalElements.StatusNode.ReadXml(reader); parsed = true; break; case Scenes.ELEMENT_NAME: optionalElements.ScenesNode = new Scenes(); optionalElements.ScenesNode.ReadXml(reader); parsed = true; break; case Description.ELEMENT_NAME: optionalElements.DescriptionNode = new Description(); optionalElements.DescriptionNode.ReadXml(reader); parsed = true; break; case Thumbnail.ELEMENT_NAME: optionalElements.ThumbnailNode = new Thumbnail(); optionalElements.ThumbnailNode.ReadXml(reader); parsed = true; break; } return parsed; } catch (Exception) { //TODO Log error return false; } }
public async Task TreeList() { //List of trees Dictionary <string, int> TreeToID = new Dictionary <string, int>() { { "Normal", 1 }, { "Achey", 1 }, { "Oak", 15 }, { "Willow", 30 }, { "Teak", 35 }, { "Maple", 45 }, { "Hollow", 45 }, { "Mahogany", 50 }, { "Arctic Pine", 54 }, { "Yew", 60 }, { "Sulliuscep", 65 }, { "Magic", 75 }, { "Redwood", 90 } }; //Okay let's get the User Woodcutting wc; using (var uow = DBHandler.UnitOfWork()) { wc = uow.Woodcutting.GetOrCreateWoodcutting(Context.User.Id); } //wowoowowwowo EmbedBuilder emb = new EmbedBuilder().WithTitle("Woodcutting | Trees"); //New field EmbedFieldBuilder embF = new EmbedFieldBuilder().WithName("You can chop these"); string str = ""; //Lets get the ones we CAN cut foreach (KeyValuePair <string, int> Tree in TreeToID) { if (wc.Level >= Tree.Value) { //Aa? string logName = Tree.Key.ToLower().Replace(' ', '_'); double XPperLog = TreeXP[TreeID[logName]]; //Aaa str += $"{Tree.Key} | Level: {Tree.Value} | XP Per Log: {XPperLog} | Log Value: {LogValues[TreeID[logName]]}\n"; } } //Add to field embF = embF.WithValue(str); //Neewwww EmbedFieldBuilder embF2 = new EmbedFieldBuilder().WithName("You cannot chop these"); string str2 = ""; //Stuff you can't do //Lets get the ones we CAN cut foreach (KeyValuePair <string, int> Tree in TreeToID) { if (wc.Level < Tree.Value) { //Aa? string logName = Tree.Key.ToLower().Replace(' ', '_'); double XPperLog = TreeXP[TreeID[logName]]; //Aaa str2 += $"{Tree.Key} | Level: {Tree.Value} | XP Per Log: {XPperLog}\n"; } } if (str2 == "") { str2 = "*You can now chop all trees.*"; } //Add to field embF2 = embF2.WithValue(str2); //Add fields Embed embDone = emb.AddField(embF).AddField(embF2).WithOkColour().Build(); //Respond await Context.Channel.BlankEmbedAsync(embDone); }
public static Task <RestUserMessage> ReplyAsync(this SocketMessage message, string text = null, bool isTTS = false, Embed embed = null, AllowedMentions mentions = null, RequestOptions options = null) => message.Channel.SendMessageAsync(text, isTTS, embed, options, mentions);
public void AddEmbed(Embed embed) { pages.Add(embed); }