Skip to content

Commit eadcd8b

Browse files
committed
Добавьте файлы проекта.
1 parent 6cee31d commit eadcd8b

5 files changed

Lines changed: 270 additions & 0 deletions

File tree

NotPixelBt.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34525.116
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NotPixelBt", "NotPixelBt\NotPixelBt.csproj", "{905FA820-CE1F-4063-A10F-C8867ECC2C1D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{905FA820-CE1F-4063-A10F-C8867ECC2C1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{905FA820-CE1F-4063-A10F-C8867ECC2C1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{905FA820-CE1F-4063-A10F-C8867ECC2C1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{905FA820-CE1F-4063-A10F-C8867ECC2C1D}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {7D365148-8BBF-4556-B314-B77C801D73F8}
24+
EndGlobalSection
25+
EndGlobal

NotPixelBt/Bot.cs

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
using OpenQA.Selenium;
2+
using OpenQA.Selenium.Chrome;
3+
using OpenQA.Selenium.DevTools;
4+
using OpenQA.Selenium.DevTools.V127.HeapProfiler;
5+
using OpenQA.Selenium.Interactions;
6+
using OpenQA.Selenium.Support.UI;
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Linq;
10+
using System.Text;
11+
using System.Threading.Tasks;
12+
13+
namespace NotPixelBt
14+
{
15+
public class Bot
16+
{
17+
public int Clicks;
18+
public bool Loged;
19+
public ChromeDriver Driver;
20+
21+
public Bot()
22+
{
23+
ChromeOptions options = new ChromeOptions();
24+
options.AddArgument("--log-level=3");
25+
Clicks = 0;
26+
Loged = false;
27+
Driver = new ChromeDriver(options);
28+
}
29+
30+
public void StartBot()
31+
{
32+
Console.WriteLine("Запуск страницы авторизации");
33+
34+
Driver.Navigate().GoToUrl("https://web.telegram.org/a/");
35+
36+
Loged = IsLoged();
37+
38+
while (Loged == false)
39+
Loged = IsLoged();
40+
if (Loged)
41+
Logger.LogInfo("Авторизация пройдена");
42+
43+
Console.WriteLine("Запустите приложение, кликните на пиксель и нажмите enter для продолжения");
44+
Console.ReadLine();
45+
Logger.LogInfo("Запуск бота");
46+
47+
Initilize();
48+
}
49+
public void RestartBot()
50+
{
51+
try
52+
{
53+
Logger.LogWarning("Бот крашнулся идет перезапуск");
54+
Logger.LogInfo("Обновление страницы");
55+
Driver.Navigate().Refresh();
56+
57+
WebDriverWait webDriverWait = new WebDriverWait(Driver, TimeSpan.FromSeconds(120));
58+
59+
IWebElement chatScroll = webDriverWait.Until(x => x.FindElement(By.Id("LeftColumn-main")));
60+
IWebElement NotPixelChat = null;
61+
62+
Logger.LogInfo("Поиск чата");
63+
while (NotPixelChat == null)
64+
{
65+
Thread.Sleep(2000);
66+
List<IWebElement> chats = chatScroll.FindElements(By.TagName("a")).Where(x => x.Text != "").ToList();
67+
foreach (IWebElement chat in chats)
68+
{
69+
string chatTitle = chat.FindElement(By.TagName("h3")).Text;
70+
if (chatTitle.Contains("Not Pixel"))
71+
{
72+
NotPixelChat = chat;
73+
NotPixelChat.Click();
74+
break;
75+
}
76+
}
77+
if (NotPixelChat != null)
78+
{
79+
Logger.LogInfo("Чат найден");
80+
break;
81+
}
82+
83+
84+
chats.Last().Click();
85+
chats.Last().SendKeys(Keys.PageDown);
86+
87+
Thread.Sleep(2000);
88+
}
89+
90+
Logger.LogInfo("Запуск приложения");
91+
92+
IWebElement messageWindow = webDriverWait.Until(x => x.FindElement(By.Id("MiddleColumn")));
93+
List<IWebElement> buttons = messageWindow.FindElements(By.TagName("button")).ToList();
94+
IWebElement goButton = buttons.First(x => x.Text == "start");
95+
96+
goButton.Click();
97+
98+
Logger.LogInfo("Ожидание полной загрузки");
99+
100+
Thread.Sleep(10000);
101+
102+
Initilize();
103+
}
104+
catch (Exception ex)
105+
{
106+
Logger.LogError(ex.ToString());
107+
RestartBot();
108+
}
109+
}
110+
private void Initilize()
111+
{
112+
try
113+
{
114+
WebDriverWait webDriverWait = new WebDriverWait(Driver,TimeSpan.FromSeconds(120));
115+
webDriverWait.Until(x => x.SwitchTo().Frame(0));
116+
117+
Logger.LogInfo("Захват холста");
118+
IWebElement gameCanvas = webDriverWait.Until(x => x.FindElement(By.Id("canvasHolder")));
119+
120+
gameCanvas.Click();
121+
122+
IWebElement energyButton = webDriverWait.Until(x => x.FindElement(By.ClassName("_button_text_hqiqj_171") ));
123+
124+
Console.WriteLine("Нажмите Enter что бы выйти");
125+
126+
ConsoleKeyInfo cki = new ConsoleKeyInfo();
127+
while (true)
128+
{
129+
Thread.Sleep(500);
130+
if (Console.KeyAvailable == true)
131+
{
132+
cki = Console.ReadKey(true);
133+
134+
if (cki.Key == ConsoleKey.Enter)
135+
{
136+
DisableBot();
137+
break;
138+
}
139+
}
140+
Thread.Sleep(100);
141+
if (energyButton.Text != "No energy")
142+
{
143+
PaintPixel(gameCanvas, energyButton);
144+
}
145+
}
146+
147+
}
148+
catch (Exception ex)
149+
{
150+
Logger.LogError(ex.ToString());
151+
RestartBot();
152+
}
153+
154+
}
155+
156+
private void PaintPixel(IWebElement gameCanvas, IWebElement energyButton)
157+
{
158+
int height = int.Parse(gameCanvas.GetAttribute("height"));
159+
int width = int.Parse(gameCanvas.GetAttribute("width"));
160+
161+
Random rnd = new Random();
162+
int ofsetX = rnd.Next(1,width);
163+
int ofsetY = rnd.Next(1,height)*-1;
164+
165+
Actions actions = new Actions(Driver);
166+
actions.MoveToElement(gameCanvas,ofsetX,ofsetY).DoubleClick();
167+
168+
//gameCanvas.Click();
169+
energyButton.Click();
170+
Clicks++;
171+
Logger.LogInfo($"Раскрашен пиксель X:{ofsetX} Y:{ofsetY}\n" +
172+
$"Сделано кликов {Clicks}");
173+
}
174+
175+
private void DisableBot()
176+
{
177+
Driver.Quit();
178+
Console.WriteLine($"Собрано {Clicks}");
179+
}
180+
private bool IsLoged()
181+
{
182+
IWebElement element = Driver.FindElement(By.TagName("h1"));
183+
184+
if (element.Text == "Log in to Telegram by QR Code") return false;
185+
186+
return true;
187+
}
188+
public void ScrollTo(int xPosition = 0, int yPosition = 0)
189+
{
190+
191+
var js = String.Format("window.scrollTo({0}, {1})", xPosition, yPosition);
192+
Driver.ExecuteScript(js);
193+
}
194+
}
195+
}

NotPixelBt/Logger.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace NotPixelBt
2+
{
3+
public static class Logger
4+
{
5+
public static void LogInfo(string info)
6+
{
7+
Console.WriteLine($"[{DateTime.Now} INFO]-{info}");
8+
}
9+
10+
public static void LogWarning(string warning)
11+
{
12+
Console.ForegroundColor = ConsoleColor.Yellow;
13+
Console.WriteLine($"[{DateTime.Now} WARN]-{warning}");
14+
Console.ResetColor();
15+
}
16+
public static void LogError(string error)
17+
{
18+
Console.ForegroundColor = ConsoleColor.Red;
19+
Console.WriteLine($"[{DateTime.Now} ERROR]-{error}");
20+
Console.ResetColor();
21+
}
22+
}
23+
}

NotPixelBt/NotPixelBt.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Selenium.WebDriver" Version="4.25.0" />
12+
</ItemGroup>
13+
</Project>

NotPixelBt/Program.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using NotPixelBt;
2+
using OpenQA.Selenium;
3+
using OpenQA.Selenium.Chrome;
4+
5+
internal class Program
6+
{
7+
private static void Main(string[] args)
8+
{
9+
Bot bot = new Bot();
10+
bot.StartBot();
11+
12+
//bot.RestartBot();
13+
}
14+
}

0 commit comments

Comments
 (0)