Compare commits
12 Commits
7b9342e6e1
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e6f6dc75d | |||
| e5693edc49 | |||
| f35288a33e | |||
| 1afcda905c | |||
| 7fab914c78 | |||
| 0c0e788966 | |||
| 766097d9f6 | |||
| c6c9688708 | |||
| a9c9a7779b | |||
| 966241a4aa | |||
| 033415a2b4 | |||
| bcf72d68b9 |
16
.drone.yml
Normal file
16
.drone.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
kind: pipeline
|
||||
type: exec
|
||||
name: backend
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
commands:
|
||||
- docker-compose build
|
||||
|
||||
- name: publish
|
||||
commands:
|
||||
- docker-compose up -d
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- master
|
||||
@@ -1,6 +1,17 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Budet-cho-bot", "Budet-cho-bot\Budet-cho-bot.csproj", "{9BF9C0C5-C025-425B-AB1C-6153C3827A76}"
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32901.215
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Budet-cho-bot", "Budet-cho-bot\Budet-cho-bot.csproj", "{9BF9C0C5-C025-425B-AB1C-6153C3827A76}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EB4C3182-A0DD-4386-8E3B-4DEE4A72F3E4}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.drone.yml = .drone.yml
|
||||
.gitignore = .gitignore
|
||||
Config.json = Config.json
|
||||
docker-compose.yml = docker-compose.yml
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -13,4 +24,10 @@ Global
|
||||
{9BF9C0C5-C025-425B-AB1C-6153C3827A76}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9BF9C0C5-C025-425B-AB1C-6153C3827A76}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E871DB37-3CF2-4EE2-AC63-3288B409205C}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
19
Budet-cho-bot/Dockerfile
Normal file
19
Budet-cho-bot/Dockerfile
Normal file
@@ -0,0 +1,19 @@
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
|
||||
WORKDIR /app
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["/Budet-cho-bot", "Budet-cho-bot"]
|
||||
COPY ["/Config.json", "Config.json"]
|
||||
RUN dotnet restore "Budet-cho-bot/Budet-cho-bot.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/Budet-cho-bot"
|
||||
RUN dotnet build "Budet-cho-bot.csproj" -c Release -o /app/publish
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "Budet-cho-bot.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base as final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "Budet-cho-bot.dll", "--environment=Development"]
|
||||
@@ -1,19 +1,18 @@
|
||||
using Discord.Commands;
|
||||
using Discord.Commands.Builders;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Discord_Bot
|
||||
{
|
||||
public class ReminderModule : ModuleBase<SocketCommandContext>
|
||||
{
|
||||
private const long DAY_PERIOD = 24 * 60 * 60 * 1000; // 10 * 1000; //
|
||||
private const long DAY_PERIOD = 24 * 60 * 60 * 1000; // 10 * 1000; //
|
||||
private Timer reminderTimer;
|
||||
|
||||
protected override void OnModuleBuilding(CommandService commandService, ModuleBuilder builder)
|
||||
[Command("reloadTimer")]
|
||||
private async Task SetReloadTimer()
|
||||
{
|
||||
base.OnModuleBuilding(commandService, builder);
|
||||
Console.WriteLine($"{DateTime.Now.TimeOfDay:hh\\:mm\\:ss} | hello world ");
|
||||
ReloadTimers();
|
||||
await ReplyAsync($"Заебись");
|
||||
}
|
||||
|
||||
[Command("remindertime")]
|
||||
@@ -28,6 +27,7 @@ namespace Discord_Bot
|
||||
private async Task SetSequence([Remainder]string message = "")
|
||||
{
|
||||
SaveToConfig("sequence", message);
|
||||
SaveToConfig("sequenceIndex", "0");
|
||||
await ReplyAsync($"Заебись");
|
||||
}
|
||||
|
||||
@@ -40,30 +40,87 @@ namespace Discord_Bot
|
||||
|
||||
private void ReloadTimers()
|
||||
{
|
||||
var time = Functions.GetConfigItem("reminderTime");
|
||||
if (time.Type == JTokenType.Boolean)
|
||||
return;
|
||||
|
||||
var nextReminder = Utility.ParseTime(time.ToString());
|
||||
var reminder = GetReminderTime();
|
||||
var now = DateTime.Now;
|
||||
|
||||
var span = (nextReminder - now).TotalMilliseconds;
|
||||
var span = (reminder - now).TotalMilliseconds;
|
||||
if (span < 0)
|
||||
{
|
||||
// skip to next day
|
||||
nextReminder = nextReminder.AddDays(1);
|
||||
span = (nextReminder - now).TotalMilliseconds;
|
||||
// skip to next period
|
||||
var d = (now - reminder).TotalMilliseconds + DAY_PERIOD;
|
||||
reminder = reminder.AddMilliseconds(d);
|
||||
span = (reminder - now).TotalMilliseconds;
|
||||
}
|
||||
|
||||
reminderTimer = new Timer(SendReminder, "sd", (long)span, DAY_PERIOD);
|
||||
|
||||
RecalcSequenceIndex();
|
||||
}
|
||||
|
||||
private DateTime GetReminderTime()
|
||||
{
|
||||
var time = Functions.GetConfigItem("reminderTime");
|
||||
if (time.Type == JTokenType.Boolean)
|
||||
return DateTime.Now;
|
||||
|
||||
return Utility.ParseTime(time.ToString());
|
||||
}
|
||||
|
||||
private async void SendReminder(object? state)
|
||||
{
|
||||
//check sequence
|
||||
|
||||
if (!CheckSequenceAndIncrementIndex())
|
||||
return;
|
||||
|
||||
var users = Functions.GetConfigItem("users").ToString();
|
||||
await ReplyAsync($"{users}\nБудет чо?");
|
||||
var message = $"{users}\nБудет чо? {DateTime.Now}";
|
||||
await ReplyAsync(message);
|
||||
}
|
||||
|
||||
private void RecalcSequenceIndex()
|
||||
{
|
||||
var reminder = GetReminderTime();
|
||||
var now = DateTime.Now;
|
||||
var sequence = GetSequence();
|
||||
|
||||
var span = (now - reminder).TotalMilliseconds;
|
||||
var spanMinusFullSequences = (int)MathF.Floor((float)span % (DAY_PERIOD * sequence.Length));
|
||||
var index = spanMinusFullSequences / DAY_PERIOD;
|
||||
SaveToConfig("sequenceIndex", index.ToString());
|
||||
}
|
||||
|
||||
private bool CheckSequenceAndIncrementIndex()
|
||||
{
|
||||
var sequenceIndex = GetSequenceIndex();
|
||||
var sequence = GetSequence();
|
||||
if (string.IsNullOrEmpty(sequence))
|
||||
return true;
|
||||
|
||||
var result = sequence[sequenceIndex] == '!';
|
||||
sequenceIndex = (sequenceIndex + 1) % sequence.Length;
|
||||
SaveToConfig("sequenceIndex", sequenceIndex.ToString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private int GetSequenceIndex()
|
||||
{
|
||||
var sequenceIndexToken = Functions.GetConfigItem("sequenceIndex");
|
||||
if (sequenceIndexToken.Type == JTokenType.Boolean)
|
||||
{
|
||||
SaveToConfig("sequenceIndex", "0");
|
||||
return 0;
|
||||
}
|
||||
return (int)sequenceIndexToken;
|
||||
}
|
||||
|
||||
private string GetSequence()
|
||||
{
|
||||
var sequenceIndexToken = Functions.GetConfigItem("sequence");
|
||||
if (sequenceIndexToken.Type == JTokenType.Boolean)
|
||||
{
|
||||
SaveToConfig("sequence", "");
|
||||
return "";
|
||||
}
|
||||
return sequenceIndexToken.ToString();
|
||||
}
|
||||
|
||||
private void SaveToConfig(string key, string data)
|
||||
|
||||
9
docker-compose.yml
Normal file
9
docker-compose.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
version: '3.4'
|
||||
|
||||
services:
|
||||
bot:
|
||||
image: bot
|
||||
container_name: bot
|
||||
build:
|
||||
context: ./
|
||||
dockerfile: Budet-cho-bot/Dockerfile
|
||||
Reference in New Issue
Block a user