public ScanMachine(ILazySocketClient client, IConfig config)
        {
            _client = client ?? throw new ArgumentNullException(nameof(client));
            _config = config ?? throw new ArgumentNullException(nameof(config));

            SentResponse = _sentResponse.Where(r => r != null);
        }
Example #2
0
 public static async Task <Response> TryCreateSayAsync(ILazySocketClient client, string message, ulong channelId, ulong?userIdOfReplyTo = null)
 {
     if (client == null)
     {
         throw new ArgumentNullException(nameof(client));
     }
     return(await TryCreateAsync(ResponseType.Say, client, message, channelId, userIdOfReplyTo));
 }
 public AllInstances(ILazySocketClient client, IConfig config)
 {
     if (client == null)
     {
         throw new ArgumentNullException(nameof(client));
     }
     Scan         = new ScanMachine(client, config ?? throw new ArgumentNullException(nameof(config)));
     SentResponse = Scan.SentResponse;
 }
Example #4
0
        protected override async Task <Response> InvokeCoreAsync(ILazySocketClient client, ILazySocketMessageChannel channel, ILazySocketUser user)
        {
            var dice       = _diceOption.Value ?? Expr.Main.Interpret("1d100").Value;
            var maxSize    = _maxSizeOption.Value ?? int.MaxValue;
            var noProgress = _noProgressOption.HasOption;
            var force      = _forceOption.HasOption;
            await _scanMachine.StartAsync(channel, user, force, dice, maxSize, noProgress);

            return(Response.None);
        }
        public MessageEntrance(ILazySocketClient client, IConfig config)
        {
            _client = client ?? throw new ArgumentNullException(nameof(client));
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }


            _basicMachines = new BasicMachines.AllInstances(client, config);

            ResponseSent = _basicMachines.SentResponse.Merge(_manualResponseSent).Where(r => r != null);
        }
Example #6
0
        protected override async Task <Response> InvokeCoreAsync(ILazySocketClient client, ILazySocketMessageChannel channel, ILazySocketUser user)
        {
            var noResult = _noResultOption.HasOption;

            if (noResult)
            {
                await _scanMachine.AbortAsync(await channel.GetIdAsync(), await user.GetIdAsync());
            }
            else
            {
                await _scanMachine.EndAsync(await channel.GetIdAsync(), await user.GetIdAsync());
            }
            return(Response.None);
        }
Example #7
0
        public async Task <Response> InvokeAsync(RawCommand command, ILazySocketClient client, ulong channelId, ulong userId)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var channel = await client.TryGetMessageChannelAsync(channelId);

            var user = await client.TryGetUserAsync(userId);

            if (channel == null || user == null)
            {
                return(Response.None);
            }
            if (command == null)
            {
                return(Response.None);
            }
            if (!CanInvoke(command))
            {
                return(Response.None);
            }

            if (command.HasDuplicateOption)
            {
                return(await Response.TryCreateCautionAsync(client, "同名のオプションが複数あります。", channelId, userId));
            }
            var usedCommand = new HashSet <CommandOption>(new RefereneEqualsEqualityComparer <CommandOption>());

            foreach (var pair in command.Options)
            {
                var found = (Options ?? new CommandOption[] { }).FirstOrDefault(option => option.Keys.Contains(pair.name));
                if (found == null)
                {
                    return(await Response.TryCreateCautionAsync(client, Texts.Error.Commands.Options.ContainsNotSupportedOption(pair.name), channelId, userId) ?? Response.None);
                }
                if (!usedCommand.Add(found))
                {
                    return(await Response.TryCreateCautionAsync(client, "同じ意味のオプションが複数あります。", channelId, userId));
                }
                var result = found.SetValue(pair.name, pair.values);
                if (!result.HasValue)
                {
                    return(await Response.TryCreateCautionAsync(client, result.Error ?? $"{pair.name} の値としてサポートしていない形式が使われています。", channelId, userId));
                }
            }
            return(await InvokeCoreAsync(client, channel, user) ?? Response.None);
        }
Example #8
0
        private static async Task <Response> TryCreateAsync(ResponseType type, ILazySocketClient client, string message, ulong channelId, ulong?userIdOfReplyTo = null)
        {
            var channel = await client.TryGetMessageChannelAsync(channelId);

            if (userIdOfReplyTo == null)
            {
                return(TryCreate(type, message, channel));
            }
            var replyTo = await client.TryGetUserAsync(userIdOfReplyTo.Value);

            if (replyTo == null)
            {
                return(null);
            }
            return(TryCreate(type, message, channel, replyTo));
        }
Example #9
0
 protected abstract Task <Response> InvokeCoreAsync(ILazySocketClient client, ILazySocketMessageChannel channel, ILazySocketUser user);
Example #10
0
        protected override async Task <Response> InvokeCoreAsync(ILazySocketClient client, ILazySocketMessageChannel channel, ILazySocketUser user)
        {
            await _scanMachine.GetLatestProgressAsync(channel, user, _shuffledOption.HasOption);

            return(Response.None);
        }
Example #11
0
 protected override async Task <Response> InvokeCoreAsync(ILazySocketClient client, ILazySocketMessageChannel channel, ILazySocketUser user)
 => await CommandActions.Changelog(client, channel);
Example #12
0
        public static async Task <Response> Changelog(ILazySocketClient client, ILazySocketMessageChannel channel)
        {
            var text = @"```
更新履歴

# v1.0.0 - 2019/09/08

- 使用しているライブラリを更新

# v0.3.11(beta) - 2019/05/30

- 使用しているライブラリを更新

# v0.3.10(beta) - 2019/05/18

- (開発者にのみ影響がある修正)

# v0.3.9(beta) - 2019/05/02

- 足し算や引き算の回数が非常に多い式を投稿した際、BOT内部でエラーを出していた問題を修正

# v0.3.8(beta) - 2019/05/01

- 終了後のscanを!scan-showした場合にも""途中経過""と表示されてしまっていた問題を修正

# v0.3.7(beta) - 2019/04/30

- メモリリークが起こっていたと思われる部分を修正
- メンションなしでも、例えば!scan-startのように!を最初につけることでもコマンドが実行できるようになった
- !scan-showの--shuffledは--shuffleとも書けるようになった

# v0.3.5(beta) - 2019/04/25

- Discord.NETが切断された後に再接続された際、それ以降ダイスなどの結果が多重に書き込まれることがあった問題を修正

# v0.3.4(beta) - 2019/04/23

- scanができなかった問題を修正

# v0.3.3(beta) - 2019/04/21

- 乱数をメルセンヌツイスタに変更
- n面ダイスを振る際、nの値が大きすぎるとオーバーフローする問題を修正

# v0.3.2(beta) - 2019/04/20

- (開発者にのみ影響がある修正)

# v0.3.1(beta) - 2019/04/20

- 式にプラスやマイナスを含むダイスロールをした際、結果のテキストにプラスやマイナスが多重に表示されてしまう問題を修正

# v0.3.0(beta) - 2019/04/20

- 全角文字を含むダイスロールをサポート
- Scanが削除されるまでの時間を30分から2時間に延長
- BOTの止まる頻度がおそらく低下
- 使用しているライブラリを更新
```";

            return(await Response.TryCreateSayAsync(client, text, await channel.GetIdAsync()));
        }
Example #13
0
 public static async Task <Response> Version(ILazySocketClient client, ILazySocketMessageChannel channel)
 => await Response.TryCreateSayAsync(client, $"version {Texts.Version}", await channel.GetIdAsync());
Example #14
0
 public static async Task <Response> Help(ILazySocketClient client, ILazySocketMessageChannel channel, string helpMessage)
 => await Response.TryCreateSayAsync(client, $"{helpMessage}", await channel.GetIdAsync());