-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
114 lines (98 loc) · 3.86 KB
/
bot.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
108
109
110
111
112
113
114
from asyncio import sleep
import argparse
import discord, datetime
import tweepy
from config import *
def parser():
parser = argparse.ArgumentParser()
parser.add_argument("--config-file", type=str, required=True)
args = parser.parse_args()
config_file = args.config_file
return open(config_file).read()
exec(parser())
class Client(discord.Client):
running = True
async def twitterapi(self):
# Replace these with your own API keys and secrets
client_id = "X"
client_secret = "X"
consumer_key = "X"
consumer_secret = "X"
access_token = "X"
access_token_secret = "X"
bearer_token = "X"
# Authenticate the request
return tweepy.Client(consumer_key = consumer_key, consumer_secret=consumer_secret, access_token=access_token, access_token_secret=access_token_secret,bearer_token=bearer_token)
async def twittercheck(self):
api = await self.twitterapi()
tweets_array = api.search_recent_tweets(query="giveaway" or "giveaways")
for tweets in tweets_array:
for tweet in tweets:
try:
if isinstance(tweet.id, int):
api.retweet(tweet.id)
print("Tweet retweeted")
else:
continue
except AttributeError:
continue
async def pause(self):
self.running = False
print("Bot paused.")
async def continueBot(self):
self.running = True
print("Bot restored.")
async def clean(self, user_message=None, bot_message=None):
await sleep(3)
if user_message is not None:
await user_message.delete()
if bot_message is not None:
await bot_message.delete()
print("Chat cleaned")
async def send(self, ctx, content):
message = await ctx.channel.send(f"{ctx.author.mention} {content}")
print(f"Sent '{content}' to '{ctx.author}'")
await self.clean(ctx, message)
async def messageCheck(self):
channels_ids = []
for server in self.guilds:
for channel in server.channels:
if str(channel.type) == 'text':
channels_ids.append(channel.id)
print(channels_ids)
#channels_ids = [channel.id for channel in channels]
# Get a list of all chanells in the current server
for channel_id in channels_ids:
channel = self.get_channel(channel_id)
async for message in channel.history(limit=50):
if message.author != self.user:
if "react" in message.content.lower():
await message.add_reaction("\N{THUMBS UP SIGN}")
return 120
# Code from original auto-bump author
async def message(self):
self.diff = await self.messageCheck()
await sleep(self.diff)
channel = self.get_channel(channel_id)
command = await channel.send("Hi")
print("Message sent")
return command
async def on_ready(self):
print(f"Logged as {self.user}")
while self.running == True:
command = await self.message()
await self.clean(command)
async def on_message(self, message):
if message.author == self.user:
if message.content == "!pause":
await self.pause()
await self.send(message, "Bot is paused :sleeping:")
elif message.content == "!continue":
await self.continueBot()
await self.send(
message,
f"Bump is activated, next bump in {self.diff} seconds :hourglass_flowing_sand:",
)
elif message.content == "!twitter":
await self.twittercheck()
Client().run( user_token, bot=False)