예제 #1
0
    def __init__(self, instanceId):
        self.instanceId = instanceId
        os.environ["DISCORD_INSTANCE_ID"] = str(self.instanceId)

        self.discord = Discord(Game.ApplicationId, CreateFlags.Default)

        self.networkManager = self.discord.GetNetworkManager()
        self.networkManager.OnRouteUpdate = self.onRouteUpdate
        self.networkManager.OnMessage = self.onMessage

        self.peerId = self.networkManager.GetPeerId()
        self.route = None
        self.connected = False
예제 #2
0
class Game:
    # We will set it dynamically
    ApplicationId = None

    def __init__(self, instanceId):
        self.instanceId = instanceId
        os.environ["DISCORD_INSTANCE_ID"] = str(self.instanceId)

        self.discord = Discord(Game.ApplicationId, CreateFlags.Default)

        self.networkManager = self.discord.GetNetworkManager()
        self.networkManager.OnRouteUpdate = self.onRouteUpdate
        self.networkManager.OnMessage = self.onMessage

        self.peerId = self.networkManager.GetPeerId()
        self.route = None
        self.connected = False

    def onRouteUpdate(self, route):
        self.route = route
        print(f"[Discord {self.instanceId}] Route: {self.route}")

        self.onRoute()

    def onMessage(self, peerId, channelId, data):
        print(
            f"[Discord {self.instanceId}] Received from {peerId} on channel {channelId}: {repr(data)}"
        )
예제 #3
0
    def __init__(self):
        self.dfMsgs = pd.read_csv(DISCORD_FILENAME)
        self.dfMsgs["date"] = pd.to_datetime(self.dfMsgs.ts)
        self.dfMsgs.set_index("date", inplace=True)

        byChannel = self.dfMsgs.groupby(by=["channelName"]).count()
        byChannel.sort_values(by="authorname", ascending=False)

        self.channels = byChannel.index.values

        self.channelFigures = {}
        for channelName in self.channels:
            self.channelFigures[channelName] = Discord(channelName,
                                                       self.dfMsgs)
예제 #4
0
def main():
    load_dotenv()

    discord_webhook_url = os.getenv("DISCORD_WEBHOOK_URL")
    subreddit = os.getenv('REDDIT_SUBREDDIT')
    reddit_client_id = os.getenv("REDDIT_CLIENT_ID")
    reddit_client_secret = os.getenv("REDDIT_CLIENT_SECRET")

    discord = Discord(discord_webhook_url)

    # Echo to discord weblink
    reddit = Reddit(subreddit, discord.sendMsg, reddit_client_id,
                    reddit_client_secret)

    # Echo locally to test.
    # reddit = Reddit(print_details, reddit_client_id, reddit_client_secret)

    reddit.run()
예제 #5
0
        close_num = os.environ["CLOSE_NUM"]
    except:
        close_num = 20

    starting_date = pendulum.datetime(STARTING_YEAR, STARTING_MONTH,
                                      STARTING_DAY)

    if bot_type == "groupme":
        bot_id = os.environ["BOT_ID"]
        bot = GroupMe(bot_id)
    elif bot_type == "slack":
        webhook = os.environ["SLACK_WEBHOOK"]
        bot = Slack(webhook)
    elif bot_type == "discord":
        webhook = os.environ["DISCORD_WEBHOOK"]
        bot = Discord(webhook)

    bot.send(get_welcome_string)  # inital message to send
    schedule.every().thursday.at("19:00").do(
        bot.send, get_matchups_string,
        league_id)  # Matchups Thursday at 4:00 pm ET
    schedule.every().friday.at("12:00").do(
        bot.send, get_scores_string, league_id)  # Scores Friday at 12 pm ET
    schedule.every().sunday.at("23:00").do(
        bot.send, get_close_games_string, league_id,
        int(close_num))  # Close games Sunday on 7:00 pm ET
    schedule.every().monday.at("12:00").do(
        bot.send, get_scores_string, league_id)  # Scores Monday at 12 pm ET
    schedule.every().tuesday.at("15:00").do(
        bot.send, get_standings_string,
        league_id)  # Standings Tuesday at 11:00 am ET
예제 #6
0
def get_player_stats(search_object):

    today = pendulum.today()
    starting_date = pendulum.datetime(STARTING_YEAR, STARTING_MONTH, STARTING_DAY)
    if starting_date >= today:
        year = STARTING_YEAR
    else:
        year = int(STARTING_YEAR) - 1
    stats = Stats(). get_all_stats("regular",year)

    bot_type = os.environ["BOT_TYPE"]


    if bot_type == "groupme":
        bot_id = os.environ["BOT_ID"]
        bot = GroupMe(bot_id)
    elif bot_type == "slack":
        webhook = os.environ["SLACK_WEBHOOK"]
        bot = Slack(webhook)
    elif bot_type == "discord":
        webhook = os.environ["DISCORD_WEBHOOK"]
        bot = Discord(webhook)
    stats_run = True
    player_id = search_object[0]
    player_name = search_object[1]
    position = search_object[2]
    team = search_object[3]
    if search_object[4] == None:
        injury_status = 'Active'
    else:
        injury_status = search_object[4]
    try:
        player = stats[player_id]
    except:
        stats_run = False
        pass
    if position not in ["QB","RB","WR","TE","DEF"]:
        stats_run = False
    if stats_run:
        if position is not "DEF":
            final_string = "{} ({} - {})\n{}\n\n".format(player_name, position, team, injury_status)
        else:
            final_string = "{} ({} - {})\n\n".format(player_name, position, team)

        if position is not "DEF":
            try:
                ga = int(player["gms_active"])
            except:
                ga = 0
                pass
            try:
                gp = int(player["gp"])
            except:
                gp = 0
                pass
            try:
                gs = int(player["gs"])
                pass
            except:
                gs = 0
                pass
            try:
                pts_half_ppr = player["pts_half_ppr"]
            except:
                pts_half_ppr = 0
                pass

            final_string += "Fantasy Points: {}\n\nGames Active: {}\nGames Played: {}\nGames Started: {}\n\n".format(pts_half_ppr, ga, gp, gs)

            try:
                team_snaps = player["tm_off_snp"]
                player_snaps = player["off_snp"]
                snap_perc = round((player_snaps / team_snaps)*100,2)
                final_string += "Snap Share: {}%\n".format(snap_perc)
            except:
                pass

        if "QB" in position:
            #try:
                #rating = player["pass_rtg"]
                #final_string += "Passer Rating: {}\n".format(rating)
            #except:
                #pass
            try:
                pyards = int(player["pass_yd"])
                final_string += "Passing Yards: {}\n".format(pyards)
            except:
                pass
            try:
                ptd = int(player["pass_td"])
                final_string += "Passing TDs: {}\n".format(ptd)
            except:
                pass
            try:
                ryards = int(player["rush_yd"])
                final_string += "Rushing Yards: {}\n".format(ryards)
            except:
                pass
            try:
                rtd = int(player["rush_td"])
                final_string += "Rushing TDs: {}\n".format(rtd)
            except:
                pass
            try:
                pass_int = int(player["pass_int"])
                final_string += "Interceptions {}\n".format(pass_int)
            except:
                pass
            try:
                fum = int(player["fum"])
                final_string += "Fumbles: {}\n".format(fum)
            except:
                pass
        if "RB" in position:
            try:
                ryards = int(player["rush_yd"])
                final_string += "Rushing Yards: {}\n".format(ryards)
            except:
                pass
            try:
                rtd = int(player["rush_td"])
                final_string += "Rushing TDs: {}\n".format(rtd)
            except:
                pass
            try:
                fum = int(player["fum"])
                final_string += "Fumbles: {}\n".format(fum)
            except:
                pass
            try:
                catch_perc = round((player["rec"]/player["rec_tgt"])*100,2)
                final_string += "Catch Rate: {}%\n".format(catch_perc)
            except:
                pass
            try:
                rcyards = int(player["rec_yd"])
                final_string += "Receiving Yards: {}\n".format(rcyards)
            except:
                pass
            try:
                rctd = int(player["rec_td"])
                final_string += "Receiving TDs: {}\n".format(rctd)
            except:
                pass
        if "WR" in position:
            try:
                rcyards = int(player["rec_yd"])
                final_string += "Receiving Yards: {}\n".format(rcyards)
            except:
                pass
            try:
                rctd = int(player["rec_td"])
                final_string += "Receiving TDs: {}\n".format(rctd)
            except:
                pass
            try:
                drop_perc = round((player["rec"]/player["rec_tgt"])*100,2)
                final_string += "Catch Rate: {}%\n".format(drop_perc)
            except:
                pass
            try:
                ryards = int(player["rush_yd"])
                final_string += "Rushing Yards: {}\n".format(ryards)
            except:
                pass
            try:
                rtd = int(player["rush_td"])
                final_string += "Rushing TDs: {}\n".format(rtd)
            except:
                pass
            try:
                fum = int(player["fum"])
                final_string += "Fumbles: {}\n".format(fum)
            except:
                pass
        if "TE" in position:
            try:
                rcyards = int(player["rec_yd"])
                final_string += "Receiving Yards: {}\n".format(rcyards)
            except:
                pass
            try:
                rctd = int(player["rec_td"])
                final_string += "Receiving TDs: {}\n".format(rctd)
            except:
                pass
            try:
                drop_perc = round((player["rec"]/player["rec_tgt"])*100,2)
                final_string += "Catch Rate: {}%\n".format(drop_perc)
            except:
                pass
            try:
                ryards = int(player["rush_yd"])
                final_string += "Rushing Yards: {}\n".format(ryards)
            except:
                pass
            try:
                rtd = int(player["rush_td"])
                final_string += "Rushing TDs: {}\n".format(rtd)
            except:
                pass
            try:
                fum = int(player["fum"])
                final_string += "Fumbles: {}\n".format(fum)
            except:
                pass
        if "K" in position:
            try:
                fga = int(player["fga"])
                fgm = int(player["fgm"])
                fgperc = round((fgm/fga)*100,2)
                final_string += "FG%: {}\n\nField Goals Attempted: {}\nField Goals Made: {}\n".format(fgperc, fga, fgm)
            except:
                pass
            try:
                fgm = int(player["fgm"])
                final_string += "Field Goals Made: {}\n".format(fgm)
            except:
                pass
            try:
                fgm1 = int(player["fgm_0_19"])
                final_string += "0-19: {}\n".format(fgm1)
            except:
                pass
            try:
                fgm2 = int(player["fgm_20_29"])
                final_string += "20-29: {}\n".format(fgm2)
            except:
                pass
            try:
                fgm3 = int(player["fgm_30_39"])
                final_string += "30-39: {}\n".format(fgm3)
            except:
                pass
            try:
                fgm4 = int(player["fgm_40_49"])
                final_string += "40-49: {}\n".format(fgm4)
            except:
                pass
            try:
                fgm5 = int(player["fgm_50p"])
                final_string += "50+: {}\n".format(fgm5)
            except:
                pass
            try:
                xpa = int(player["xpa"])
                xpm = int(player["xpm"])
                xpperc = round((xpm/xpa)*100,2)
                final_string += "XP%: {}\n\nXP Attempted: {}\nXP Made: {}\n".format(xpperc, xpa, xpm)
            except:
                pass
        if "DEF" in position:
            try:
                td = int(player["td"])
                final_string += "Touchdowns: {}\n".format(td)
            except:
                pass
            try:
                ff = int(player["ff"])
                final_string += "Forced Fumbles: {}\n".format(ff)
            except:
                pass
            try:
                fum_rec = int(player["fum_rec"])
                final_string += "Fumbles Recoved: {}\n".format(fum_rec)
            except:
                pass
            try:
                tkl = int(player["tkl_loss"])
                final_string += "Tackles For Loss: {}\n".format(tkl)
            except:
                pass
            try:
                qbh = int(player["qb_hit"])
                final_string += "QB Hits: {}\n".format(qbh)
            except:
                pass
            try:
                sck = int(player["sack"])
                final_string += "Sacks: {}\n".format(sck)
            except:
                pass
    else:
        if player_name == "Aaron Hernandez":
            final_string = "{} hung himself. Gone Forever! Aaron Hernandez.".format(player_name)
        elif position not in ["QB","RB","WR","TE"]:
            final_string = "I do not do IDP stats"
        else:
            final_string = "No {} stats found for {}".format(year, player_name)

    bot.send(send_any_string, final_string)
예제 #7
0
def get_player_key(search_string, requestor, name_key_switch):
    players = Players().get_all_players()
    bot_type = os.environ["BOT_TYPE"]

    if bot_type == "groupme":
        bot_id = os.environ["BOT_ID"]
        bot = GroupMe(bot_id)
    elif bot_type == "slack":
        webhook = os.environ["SLACK_WEBHOOK"]
        bot = Slack(webhook)
    elif bot_type == "discord":
        webhook = os.environ["DISCORD_WEBHOOK"]
        bot = Discord(webhook)

    found_players = []
    if name_key_switch == 0:
        for player_id in players:
            player = players[player_id]
            try:
                token_set_ratio = fuzz.token_set_ratio(search_string, player["search_full_name"])
                try:
                    injury_status = player["injury_status"]
                except:
                    injury_status = None
                if search_string in player["search_full_name"]:
                    found_players.append((player_id, player["full_name"], player["position"], player["team"], injury_status))
                elif token_set_ratio > 79:
                    found_players.append((player_id, player["full_name"], player["position"], player["team"], injury_status))
            except:
                pass
            if player["position"] == "DEF":
                search_name = player["first_name"].lower() + player["last_name"].lower()
                search_name = search_name.replace(" ","")
                full_name_clean = player["first_name"] + " " + player["last_name"]
                def_ratio = fuzz.ratio(search_string, search_name)
                try:
                    injury_status = player["injury_status"]
                except:
                    injury_status = None
                if def_ratio > 54:
                    found_players.append((player_id, full_name_clean, player["position"], player["team"], injury_status))
        if len(found_players) > 1:
            text = "Which player are you looking for?\n\n"
            for p in found_players:
                text += "for {} ({} - {}) - reply {}\n\n".format(p[1], p[2], p[3], p[0])
            bot.send(send_any_string, text)
            return "True"
        elif len(found_players) == 1:
            get_player_stats(found_players[0])
            return "False"
        elif len(found_players) == 0:
            bot.send(send_any_string, 'Player not found')
            return "False"
    elif name_key_switch == 1:
        player = players[search_string]
        if player["position"] == "DEF":
            full_name_clean = player["first_name"] + " " + player["last_name"]
            try:
                injury_status = player["injury_status"]
            except:
                injury_status = None
            found_players.append((search_string, full_name_clean, player["position"], player["team"], injury_status))
        else:
            try:
                injury_status = player["injury_status"]
            except:
                injury_status = None
            found_players.append((search_string, player["full_name"], player["position"], player["team"], injury_status))
        get_player_stats(found_players[0])
        return "False"
예제 #8
0
def get_depth_chart(team, position):
    players = Players().get_all_players()

    bot_type = os.environ["BOT_TYPE"]

    if bot_type == "groupme":
        bot_id = os.environ["BOT_ID"]
        bot = GroupMe(bot_id)
    elif bot_type == "slack":
        webhook = os.environ["SLACK_WEBHOOK"]
        bot = Slack(webhook)
    elif bot_type == "discord":
        webhook = os.environ["DISCORD_WEBHOOK"]
        bot = Discord(webhook)

    final_string = "Depth Chart for {} - {}\n\n".format(team, position)
    if position == 'WR':
        lwrdc_num = []
        rwrdc_num = []
        swrdc_num = []
        for player_id in players:
            player = players[player_id]
            if player["team"] == team and player["position"] == position:
                if player["depth_chart_order"] is not None:
                    if player["depth_chart_position"] == 'LWR':
                        lwrdc_num.append(player["depth_chart_order"])
                    elif player["depth_chart_position"] == 'RWR':
                        rwrdc_num.append(player["depth_chart_order"])
                    elif player["depth_chart_position"] == 'SWR':
                        swrdc_num.append(player["depth_chart_order"])
        if len(lwrdc_num) > 0:
            lwrdc_cnt = max(lwrdc_num)
            i =1
            final_string += "WR1:\n"
            while i <= lwrdc_cnt:
                for player_id in players:
                    player = players[player_id]
                    if team == player["team"] and position == player["position"] and player["depth_chart_position"] == 'LWR' and i == player["depth_chart_order"]:
                        final_string += "{}. {}\n".format(i, player["full_name"])
                i += 1
            final_string += "\n"
        if len(rwrdc_num) > 0:
            rwrdc_cnt = max(rwrdc_num)
            i =1
            final_string += "WR2:\n"
            while i <= rwrdc_cnt:
                for player_id in players:
                    player = players[player_id]
                    if team == player["team"] and position == player["position"] and player["depth_chart_position"] == 'RWR' and i == player["depth_chart_order"]:
                        final_string += "{}. {}\n".format(i, player["full_name"])
                i += 1
            final_string += "\n"
        if len(swrdc_num) > 0:
            swrdc_cnt = max(swrdc_num)
            i = 1
            final_string += "WR3:\n"
            while i <= swrdc_cnt:
                for player_id in players:
                    player = players[player_id]
                    if team == player["team"] and position == player["position"] and player["depth_chart_position"] == 'SWR' and i == player["depth_chart_order"]:
                        final_string += "{}. {}\n".format(i, player["full_name"])
                i += 1
            final_string += "\n"
    else:
        dc_num = []
        for player_id in players:
            player = players[player_id]
            if player["team"] == team and player["position"] == position:
                if player["depth_chart_order"] is not None:
                    dc_num.append(player["depth_chart_order"])
        dc_cnt = max(dc_num)
        i = 1
        while i <= dc_cnt:
            for player_id in players:
                player = players[player_id]
                if team == player["team"] and position == player["position"] and i == player["depth_chart_order"]:
                    final_string += "{}. {}\n".format(i, player["full_name"])
            i += 1
    bot.send(send_any_string, final_string)
예제 #9
0
import argparse
import cv2
import imutils
import logging
# import the necessary packages
from imutils.video import VideoStream
from io import BytesIO

from command import Command
from discord import Discord
from embedbuilder import EmbedBuilder

total_count = 0
command = Command()
discord = Discord()


def send_message(frame):
    global total_count
    total_count += 1
    print("Triggered %i times\n", total_count)

    global discord
    builder = EmbedBuilder()
    builder.set_image(("maybecat.png", frame))
    builder.set_title("Iz this Kat?")
    builder.set_description("use /tableflip to shoo away")
    embeds = builder.get_embeds()
    discord.send(embeds=embeds)
예제 #10
0
# we get the application id from a file
with open("application_id.txt", "r") as file:
    applicationId = int(file.read())


# debug callback
def debugCallback(debug, result, *args):
    if result == Result.Ok:
        print(debug, "success")
    else:
        print(debug, "failure", result, args)


# we create the discord instance
app = Discord(applicationId, CreateFlags.Default)
activityManager = app.GetActivityManager()


# events
def onActivityJoin(secret):
    print("[onActivityJoin]")
    print("Secret", secret)


def onActivitySpectate(secret):
    print("[onActivitySpectate]")
    print("Secret", secret)


def onActivityJoinRequest(user):
예제 #11
0
# discord is in the parent folder
import sys
sys.path.insert(0, "..")

# we can now import it
from discord import Discord
from discord.enum import CreateFlags, Result, PremiumType, UserFlag
import time, uuid

# we get the application id from a file
with open("application_id.txt", "r") as file:
    applicationId = int(file.read())

# we create the discord instance
app = Discord(applicationId, CreateFlags.Default)
userManager = app.GetUserManager()


# events
def onCurrentUserUpdate():
    print("[onCurrentUserUpdate]")
    user = userManager.GetCurrentUser()
    print(f"hello, {user.Username}#{user.Discriminator}!")

    premiumType = userManager.GetCurrentUserPremiumType()
    if premiumType == PremiumType.None_:
        print("you are not a nitro subscriber :(")
    elif premiumType == PremiumType.Tier1:
        print("you are a nitro classic subscriber!")
    elif premiumType == PremiumType.Tier2:
        print("you are a nitro subscriber!")
#!/usr/bin/env python3
from scrapper import Scrapper
from discord import Discord

url = "https://www.amazon.in/dp/B0856HNLDK/ref=twister_B0859XSFF6?_encoding=UTF8&psc=1"
headers = 'Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0'
dis_url = "https://discordapp.com/api/webhooks/779391429960531978/9iej5a0xP-GpvwsrbHIwHOXTT48oMWNVnbo5kDC5WcqDXjuigBKeb2qQq_RcfLP4m6Ur"

try:
    myscrapper = Scrapper("Boat Rockerz 550", url, headers, dis_url)
    myscrapper.get_price()
except:
    er_dis = Discord(dis_url)
    er_dis.msg("Program Stoppped")
예제 #13
0
import os
from discord import Discord
from flask import Flask, request
from trello import TrelloClient

DISCORD_API_TOKEN = os.environ.get('DISCORD_API_TOKEN')
DISCORD_CHANNEL_ID = os.environ.get('DISCORD_CHANNEL_ID')
TRELLO_API_KEY = os.environ.get('TRELLO_API_KEY')
TRELLO_API_SECRET = os.environ.get('TRELLO_API_SECRET')
TRELLO_API_TOKEN = os.environ.get('TRELLO_API_TOKEN')
MODEL_ID = os.environ.get('MODEL_ID')

app = Flask(__name__)
discord = Discord(DISCORD_API_TOKEN, DISCORD_CHANNEL_ID)
trello_client = TrelloClient(api_key=TRELLO_API_KEY,
                             api_secret=TRELLO_API_SECRET,
                             token=MODEL_ID)

template = """
    **Card ID:** {} \n 
    **Requester:** {} \n
    **Assignee:** {} \n
    **Description:** \n
    ```
    {}
    ```
    """


@app.route('/', methods=['POST'])
def callback():
예제 #14
0
# discord is in the parent folder
import sys 
sys.path.insert(0, "..")

# we can now import it
from discord import Discord
from discord.enum import CreateFlags, Result, Status, RelationshipType
from discord.model import Activity
import time, random

# we get the application id from a file
with open("application_id.txt", "r") as file:
    applicationId = int(file.read())
    
# we create the discord instance
app = Discord(applicationId,  CreateFlags.Default)
relationshipManager = app.GetRelationshipManager()

# events
def onRefresh():
    print("[onRefresh]")
    
    # we filter friends
    relationshipManager.Filter(lambda relationship: relationship.Type == RelationshipType.Friend)

    # we get how many friends we have!!
    friendCount = relationshipManager.Count()
    friends = []
    print("you have " + str(friendCount) + " friends!")
    
    for n in range(friendCount):
예제 #15
0
 def send_report(self, PPrice):
     mydiscord = Discord(self.webhook_url)
     mydiscord.send_msg(self.Pname, self.desc, "Price", "₹" + str(PPrice))