public bool RemoveStartupCommand(int index, out StartupCommand cmd) { using (var uow = _db.UnitOfWork) { var cmds = uow.BotConfig .GetOrCreate(set => set.Include(x => x.StartupCommands)) .StartupCommands; cmd = cmds .FirstOrDefault(x => x.Index == index); if (cmd != null) { cmds.Remove(cmd); if (_autoCommands.TryGetValue(cmd.GuildId, out var autos)) { if (autos.TryRemove(cmd.Id, out var timer)) { timer.Change(Timeout.Infinite, Timeout.Infinite); } } uow.Complete(); return(true); } } return(false); }
// [OwnerOnly] public async Task AutoCommandAdd(int interval, [Remainder] string cmdText) { if (cmdText.StartsWith(Prefix + "die", StringComparison.InvariantCulture)) { return; } if (interval < 5) { return; } var guser = ((IGuildUser)Context.User); var cmd = new StartupCommand() { CommandText = cmdText, ChannelId = Context.Channel.Id, ChannelName = Context.Channel.Name, GuildId = Context.Guild?.Id, GuildName = Context.Guild?.Name, VoiceChannelId = guser.VoiceChannel?.Id, VoiceChannelName = guser.VoiceChannel?.Name, Interval = interval, }; _service.AddNewAutoCommand(cmd); await ReplyConfirmLocalized("autocmd_add", Format.Code(Format.Sanitize(cmdText)), cmd.Interval).ConfigureAwait(false); }
private Timer TimerFromStartupCommand(StartupCommand x) { return(new Timer(async(obj) => await ExecuteCommand((StartupCommand)obj), x, x.Interval * 1000, x.Interval * 1000)); }
public async Task StartupCommandAdd([Remainder] string cmdText) { var guser = (IGuildUser)Context.User; var cmd = new StartupCommand { CommandText = cmdText, ChannelId = Context.Channel.Id, ChannelName = Context.Channel.Name, GuildId = Context.Guild?.Id, GuildName = Context.Guild?.Name, VoiceChannelId = guser.VoiceChannel?.Id, VoiceChannelName = guser.VoiceChannel?.Name, }; uow.BotConfig.GetOrCreate().StartupCommands.Add(cmd); await uow.SaveChangesAsync(false).ConfigureAwait(false); await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithTitle(GetText("scadd")) .AddField(efb => efb.WithName(GetText("server")) .WithValue(cmd.GuildId == null ? "-" : $"{cmd.GuildName}/{cmd.GuildId}").WithIsInline(true)) .AddField(efb => efb.WithName(GetText("channel")) .WithValue($"{cmd.ChannelName}/{cmd.ChannelId}").WithIsInline(true)) .AddField(efb => efb.WithName(GetText("command_text")) .WithValue(cmdText).WithIsInline(false))); }
public async Task StartupCommandAdd([Remainder] string cmdText) { if (cmdText.StartsWith(Prefix + "die", StringComparison.InvariantCulture)) { return; } var guser = ((IGuildUser)Context.User); var cmd = new StartupCommand() { CommandText = cmdText, ChannelId = Context.Channel.Id, ChannelName = Context.Channel.Name, GuildId = Context.Guild?.Id, GuildName = Context.Guild?.Name, VoiceChannelId = guser.VoiceChannel?.Id, VoiceChannelName = guser.VoiceChannel?.Name, Interval = 0, }; _service.AddNewAutoCommand(cmd); await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithTitle(GetText("scadd")) .AddField(efb => efb.WithName(GetText("server")) .WithValue(cmd.GuildId == null ? $"-" : $"{cmd.GuildName}/{cmd.GuildId}").WithIsInline(true)) .AddField(efb => efb.WithName(GetText("channel")) .WithValue($"{cmd.ChannelName}/{cmd.ChannelId}").WithIsInline(true)) .AddField(efb => efb.WithName(GetText("command_text")) .WithValue(cmdText).WithIsInline(false))).ConfigureAwait(false); }
public async Task StartupCommandAdd([Remainder] string cmdText) { var guser = ((IGuildUser)Context.User); var cmd = new StartupCommand() { CommandText = cmdText, ChannelId = Context.Channel.Id, ChannelName = Context.Channel.Name, GuildId = Context.Guild?.Id, GuildName = Context.Guild?.Name, VoiceChannelId = guser.VoiceChannel?.Id, VoiceChannelName = guser.VoiceChannel?.Name, }; using (var uow = _db.UnitOfWork) { uow.BotConfig .GetOrCreate(set => set.Include(x => x.StartupCommands)) .StartupCommands.Add(cmd); await uow.CompleteAsync().ConfigureAwait(false); } await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithTitle(GetText("scadd")) .AddField(efb => efb.WithName(GetText("server")) .WithValue(cmd.GuildId == null ? $"-" : $"{cmd.GuildName}/{cmd.GuildId}").WithIsInline(true)) .AddField(efb => efb.WithName(GetText("channel")) .WithValue($"{cmd.ChannelName}/{cmd.ChannelId}").WithIsInline(true)) .AddField(efb => efb.WithName(GetText("command_text")) .WithValue(cmdText).WithIsInline(false))); }
public void AddNewStartupCommand(StartupCommand cmd) { using (var uow = _db.UnitOfWork) { uow.BotConfig .GetOrCreate(set => set.Include(x => x.StartupCommands)) .StartupCommands .Add(cmd); uow.Complete(); } }
private async Task OnLoadedAsync() { Thread.CurrentThread.Name = "App thread"; _host = MefHostServices.Create(MefHostServices.DefaultAssemblies); await ViewModel.LoadFileOrProjectAsync(this, this.Filename); await SetupCodeControlAsync(); StartupCommand?.Execute(null); }
private bool StartCompile() { StartupCommand compile = new StartupCommand() { Minimize = true, LazyClassLoading = false, LazyTableLoading = false, Development = true, NoModalBoxes = true, Command = "kernelcompileall" }; if (!string.IsNullOrEmpty(ConfigurationFile)) { compile.ConfigurationFile = ConfigurationFile; } if (Layercodes != null) { if (!string.IsNullOrEmpty(ModelManifest)) { string model; string publisher; string layer; string layerCode; Helper.ExtractClientLayerModelInfo(ConfigurationFile, Layercodes, ModelManifest, out model, out publisher, out layer, out layerCode); compile.Model = model; compile.ModelPublisher = publisher; compile.Layer = layer; compile.LayerCode = layerCode; } } var clientConfig = Helper.GetClientConfig(ConfigurationFile); logFile = string.Format(@"{0}\{1}", Environment.ExpandEnvironmentVariables(clientConfig.LogDirectory), "AxCompileAll.html"); Process task = null; if (string.IsNullOrEmpty(ClientExecutablePath)) { task = Client.StartCommand(compile); } else { task = Client.StartCommand(ClientExecutablePath, compile); } task.WaitForExit(); return(true); }
private bool StartCompile() { StartupCommand compile = new StartupCommand() { Minimize = true, LazyClassLoading = false, LazyTableLoading = false, Development = true, NoModalBoxes = true, Command = "preexit" }; if (!string.IsNullOrEmpty(ConfigurationFile)) { compile.ConfigurationFile = ConfigurationFile; } if (Layercodes != null) { if (!string.IsNullOrEmpty(ModelManifest)) { string model; string publisher; string layer; string layerCode; Helper.ExtractClientLayerModelInfo(ConfigurationFile, Layercodes, ModelManifest, out model, out publisher, out layer, out layerCode); compile.Model = model; compile.ModelPublisher = publisher; compile.Layer = layer; compile.LayerCode = layerCode; } } var clientConfig = Helper.GetClientConfig(ConfigurationFile); Process task = null; if (string.IsNullOrEmpty(ClientExecutablePath)) { task = Client.StartCommand(compile); } else { task = Client.StartCommand(ClientExecutablePath, compile); } task.WaitForExit(); return(true); }
private async Task ExecuteCommand(StartupCommand cmd) { var prefix = _cmdHandler.GetPrefix(cmd.GuildId); //if someone already has .die as their startup command, ignore it if (cmd.CommandText.StartsWith(prefix + "die")) { return; } await _cmdHandler.ExecuteExternal(cmd.GuildId, cmd.ChannelId, cmd.CommandText); await Task.Delay(400).ConfigureAwait(false); }
public void AddNewAutoCommand(StartupCommand cmd) { using (var uow = _db.UnitOfWork) { uow.BotConfig .GetOrCreate(set => set.Include(x => x.StartupCommands)) .StartupCommands .Add(cmd); var autos = _autoCommands.GetOrAdd(cmd.GuildId, new ConcurrentDictionary <int, Timer>()); autos.AddOrUpdate(cmd.Id, key => TimerFromStartupCommand(cmd), (key, old) => { old.Change(Timeout.Infinite, Timeout.Infinite); return(TimerFromStartupCommand(cmd)); }); uow.Complete(); } }
public bool RemoveStartupCommand(string cmdText, out StartupCommand cmd) { using (var uow = _db.UnitOfWork) { var cmds = uow.BotConfig .GetOrCreate(set => set.Include(x => x.StartupCommands)) .StartupCommands; cmd = cmds .FirstOrDefault(x => x.CommandText.ToLowerInvariant() == cmdText.ToLowerInvariant()); if (cmd != null) { cmds.Remove(cmd); uow.Complete(); return(true); } } return(false); }
private async Task ExecuteCommand(StartupCommand cmd) { try { var prefix = _cmdHandler.GetPrefix(cmd.GuildId); //if someone already has .die as their startup command, ignore it if (cmd.CommandText.StartsWith(prefix + "die", StringComparison.InvariantCulture)) { return; } await _cmdHandler.ExecuteExternal(cmd.GuildId, cmd.ChannelId, cmd.CommandText).ConfigureAwait(false); await Task.Delay(400).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } }