This repository has been archived by the owner on Oct 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
107 lines (71 loc) · 3.76 KB
/
Main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Imports
import discord
import tweepy
from discord import Webhook, AsyncWebhookAdapter
from discord.ext import commands, tasks
import aiohttp
from pymongo import MongoClient
import os
# Utils
import Utils
# Erstellen des Client für discord
intents = discord.Intents.default()
intents.members = True
client = commands.AutoShardedBot(
command_prefix=Utils.YamlContainerManagement.GET_yamlAttr("Variablen", "ClientSide", "Prefix"),
intents=intents,
case_insensitive=True)
# Tweepy
auth = tweepy.OAuthHandler(Utils.YamlContainerManagement.GET_yamlAttr("Variablen", "TwitterSide", "API_Key"),
Utils.YamlContainerManagement.GET_yamlAttr("Variablen", "TwitterSide", "API_SECRET_Key"))
auth.set_access_token(Utils.YamlContainerManagement.GET_yamlAttr("Variablen", "TwitterSide", "ACCESS_Token"),
Utils.YamlContainerManagement.GET_yamlAttr("Variablen", "TwitterSide", "ACCESS_SECRET_Token"))
api = tweepy.API(auth)
# MongoDB Initialisierung / Benachrichtigung sobald der Bot Online.
@client.listen()
async def on_ready():
client.connection_url = Utils.YamlContainerManagement.GET_yamlAttr("Variablen", "ClientSide", "MongoDB", "Connection")
Base = str(Utils.YamlContainerManagement.GET_yamlAttr("Variablen", "ClientSide", "MongoDB", "Base"))
Uccount = str(Utils.YamlContainerManagement.GET_yamlAttr("Variablen", "ClientSide", "MongoDB", "Uccount"))
Config = str(Utils.YamlContainerManagement.GET_yamlAttr("Variablen", "ClientSide", "MongoDB", "Config"))
status = int(Utils.YamlContainerManagement.GET_yamlAttr("Variablen", "ClientSide", "Status", "ID"))
Text = Utils.YamlContainerManagement.GET_yamlAttr("Variablen", "ClientSide", "Status", "Text")
game = "Destiny 2" if Text is None else Text
choiceStatus = discord.Status.online if status == 1 else discord.Status.do_not_disturb
choiceActivity = discord.Activity(type=discord.ActivityType.playing,
name=game) if status == 1 else discord.Activity(
type=discord.ActivityType.watching, name="WARTUNGSARBEITEN")
await client.change_presence(status=choiceStatus, activity=choiceActivity)
client.mongo = MongoClient(str(client.connection_url))
client.Uccount = client.mongo[Base][Uccount]
client.Config = client.mongo[Base][Config]
get_twitter.start()
print(f'DATENBANK AKTIV\n<-->\nONLINE\n<-->\n{client.user}\n<-->\nTwitter API AKTIV\n<-->')
@tasks.loop(minutes=1)
async def get_twitter():
tweetL = api.user_timeline(id=2431136251, tweet_mode="extended")
Newest_Tweet_id_String = tweetL[0].id_str
base_URL = f'https://www.twitter.com/BungieHelp/status/{Newest_Tweet_id_String}'
Newest_Tweet_Time = tweetL[0].created_at
data = client.Config.find_one({"_id": "TwitterAPI"})
if data["Time"] == Newest_Tweet_Time:
return
else:
client.Config.update_one({"_id": "TwitterAPI"}, {"$set": {"Time": Newest_Tweet_Time}})
async with aiohttp.ClientSession() as session:
url = Utils.YamlContainerManagement.GET_yamlAttr("Variablen", "ClientSide", "ClientWebhooks", "TwitterHook")
webhook = Webhook.from_url(url, adapter=AsyncWebhookAdapter(session))
message = f"{base_URL}"
await webhook.send(content=message, username="@BungieHelp",
avatar_url=client.user.avatar_url)
# Laden der Erweiterungen
x = 0
for filename in os.listdir('Extensions'):
client.load_extension(f'Extensions.{filename[:-3]}') if filename.endswith(".py") else None
x += 1
print(f"<-->\nCogs geladen! Anzahl: {x}\n<-->")
# Starten des Client mit dem Token
def token_output():
data = Utils.YamlContainerManagement.GET_yamlAttr("Variablen", "ClientSide", "Token")
return data
client.run(token_output())