Пример #1
0
        private static async Task MessageReceivedAsync(SocketMessage message)
        {
            FileGuard();

            var json       = File.ReadAllText(fileName);
            var fuckyState = JsonConvert.DeserializeObject <FuckyState>(json);

            if (message.Content.ToLower() == "!status")
            {
                var statusMessage = await GetStatusMessage(fuckyState, false);

                await message.Channel.SendMessageAsync(statusMessage);
            }
            else if (message.Content.ToLower().StartsWith("!fucky "))
            {
                fuckyState = new FuckyState
                {
                    Status    = FuckyStatus.Fucky,
                    Message   = message.Content.Substring(7).Replace(Environment.NewLine, string.Empty),
                    Timestamp = DateTimeOffset.UtcNow,
                    Username  = message.Author.Username
                };
                json = JsonConvert.SerializeObject(fuckyState);
                File.WriteAllText(fileName, json);
                var statusMessage = await GetStatusMessage(fuckyState, true);

                await message.Channel.SendMessageAsync(statusMessage);
            }
            else if (message.Content.ToLower() == "!unfucky")
            {
                fuckyState = new FuckyState
                {
                    Status    = FuckyStatus.NotFucky,
                    Timestamp = DateTimeOffset.UtcNow,
                    Username  = message.Author.Username
                };
                json = JsonConvert.SerializeObject(fuckyState);
                File.WriteAllText(fileName, json);
                var statusMessage = await GetStatusMessage(fuckyState, true);

                await message.Channel.SendMessageAsync(statusMessage);
            }
        }
Пример #2
0
 private static Task <string> GetStatusMessage(FuckyState fuckyState, bool beingSet)
 {
     return(Task.FromResult($"{(beingSet ? "Set to" : "Status is")} **{fuckyState.Status.ToString()}** set by *{fuckyState.Username}* on {fuckyState.Timestamp:F} {(string.IsNullOrEmpty(fuckyState.Message) ? "" : $"with message '{fuckyState.Message}'")}"));