mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-01-31 09:09:00 +03:00
Initial commit
This commit is contained in:
commit
3fa19a4794
8 changed files with 124 additions and 0 deletions
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
.idea/
|
||||||
|
*.user
|
||||||
|
token.txt
|
||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
/packages/
|
||||||
|
riderModule.iml
|
||||||
|
/_ReSharper.Caches/
|
16
Boyfriend-CSharp.sln
Normal file
16
Boyfriend-CSharp.sln
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Boyfriend", "Boyfriend\Boyfriend.csproj", "{21640A7A-75C2-4515-A1DF-CE8B6EEBD260}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{21640A7A-75C2-4515-A1DF-CE8B6EEBD260}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{21640A7A-75C2-4515-A1DF-CE8B6EEBD260}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{21640A7A-75C2-4515-A1DF-CE8B6EEBD260}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{21640A7A-75C2-4515-A1DF-CE8B6EEBD260}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
28
Boyfriend/Boyfriend.cs
Normal file
28
Boyfriend/Boyfriend.cs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
using Discord;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
|
||||||
|
namespace Boyfriend;
|
||||||
|
public class Boyfriend {
|
||||||
|
|
||||||
|
public static void Main(string[] args)
|
||||||
|
=> new Boyfriend().MainAsync().GetAwaiter().GetResult();
|
||||||
|
|
||||||
|
public static readonly DiscordSocketClient Client = new();
|
||||||
|
|
||||||
|
private async Task MainAsync() {
|
||||||
|
Client.Log += Log;
|
||||||
|
var token = File.ReadAllText("token.txt").Trim();
|
||||||
|
|
||||||
|
await Client.LoginAsync(TokenType.Bot, token);
|
||||||
|
await Client.StartAsync();
|
||||||
|
|
||||||
|
await new CommandHandler().InstallCommandsAsync();
|
||||||
|
|
||||||
|
await Task.Delay(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Task Log(LogMessage msg) {
|
||||||
|
Console.WriteLine(msg.ToString());
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
20
Boyfriend/Boyfriend.csproj
Normal file
20
Boyfriend/Boyfriend.csproj
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<LangVersion>default</LangVersion>
|
||||||
|
<Title>Boyfriend</Title>
|
||||||
|
<Authors>l1ttle</Authors>
|
||||||
|
<PackageProjectUrl>https://github.com/l1ttleO/Boyfriend-CSharp</PackageProjectUrl>
|
||||||
|
<RepositoryUrl>https://github.com/l1ttleO/Boyfriend-CSharp</RepositoryUrl>
|
||||||
|
<RepositoryType>git</RepositoryType>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Discord.Net" Version="2.4.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
3
Boyfriend/Boyfriend.csproj.DotSettings
Normal file
3
Boyfriend/Boyfriend.csproj.DotSettings
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:String x:Key="/Default/CodeEditing/Localization/Localizable/@EntryValue">Yes</s:String>
|
||||||
|
</wpf:ResourceDictionary>
|
29
Boyfriend/CommandHandler.cs
Normal file
29
Boyfriend/CommandHandler.cs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
using System.Reflection;
|
||||||
|
using Discord.Commands;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
|
||||||
|
namespace Boyfriend;
|
||||||
|
|
||||||
|
public class CommandHandler {
|
||||||
|
private readonly DiscordSocketClient _client = Boyfriend.Client;
|
||||||
|
private readonly CommandService _commands = new CommandService();
|
||||||
|
|
||||||
|
public async Task InstallCommandsAsync() {
|
||||||
|
_client.MessageReceived += HandleCommandAsync;
|
||||||
|
await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandleCommandAsync(SocketMessage messageParam) {
|
||||||
|
if (messageParam is not SocketUserMessage message) return;
|
||||||
|
var argPos = 0;
|
||||||
|
|
||||||
|
if (!(message.HasCharPrefix('!', ref argPos) ||
|
||||||
|
message.HasMentionPrefix(_client.CurrentUser, ref argPos)) ||
|
||||||
|
message.Author.IsBot)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var context = new SocketCommandContext(_client, message);
|
||||||
|
|
||||||
|
await _commands.ExecuteAsync(context, argPos, null);
|
||||||
|
}
|
||||||
|
}
|
12
Boyfriend/Commands/PingModule.cs
Normal file
12
Boyfriend/Commands/PingModule.cs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
using Discord.Commands;
|
||||||
|
|
||||||
|
namespace Boyfriend.Commands;
|
||||||
|
|
||||||
|
public class PingModule : ModuleBase<SocketCommandContext> {
|
||||||
|
|
||||||
|
[Command("ping")]
|
||||||
|
[Summary("Измеряет время обработки REST-запроса")]
|
||||||
|
[Alias("пинг")]
|
||||||
|
public async Task Run()
|
||||||
|
=> await ReplyAsync(Utils.GetBeep() + Boyfriend.Client.Latency + "мс");
|
||||||
|
}
|
8
Boyfriend/Utils.cs
Normal file
8
Boyfriend/Utils.cs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
namespace Boyfriend;
|
||||||
|
|
||||||
|
public static class Utils {
|
||||||
|
public static string GetBeep() {
|
||||||
|
var letters = new[] { "а", "о", "и"};
|
||||||
|
return "Б" + letters[new Random().Next(3)] + "п! ";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue